-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
68 lines (58 loc) · 1.88 KB
/
index.js
File metadata and controls
68 lines (58 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import express from "express";
import dotenv from "dotenv";
import bodyParser from "body-parser";
import cors from "cors";
import cookieParser from "cookie-parser";
// import ส่วนที่ติดตั้งเข้ามา
import swaggerUI from "swagger-ui-express";
import yaml from "yaml";
// ใช้ File
import fs from "fs";
import usersRoute from "./routes/usersRoute.js";
import adminRoute from "./routes/adminRoute.js";
import airportsRoute from "./routes/airportsRoute.js";
import cars_detailRoute from "./routes/cars_detailRoute.js";
import bookingRoute from "./routes/bookingRoute.js";
import paymentRoute from "./routes/paymentRoute.js";
import driversRoute from "./routes/driversRoute.js";
dotenv.config();
const app = express();
const port = process.env.PORT;
// swagger
const swaggerfile = fs.readFileSync("services/swagger.yaml", "utf-8");
const swaggerDoc = yaml.parse(swaggerfile);
app.use(
cors({
origin: [
"http://localhost:5173",
"http://127.0.0.1:5173",
"http://localhost",
"http://127.0.0.1",
"http://localhost:4173",
"http://127.0.0.1:4173",
], //Domain ของ Frontend
methods: ["GET", "POST", "PUT", "DELETE"], //Method ที่อนุญาต
credentials: true, //ให้ส่งข้อมูล Header+Cookie ได้
}),
);
app.use(cookieParser());
app.use("/api-docs", swaggerUI.serve, swaggerUI.setup(swaggerDoc));
app.use("/img_mem", express.static("img_mem"));
app.use("/img_cars", express.static("img_cars"));
app.use(bodyParser.json());
app.use(usersRoute);
app.use(adminRoute);
app.use(airportsRoute);
app.use(cars_detailRoute);
app.use(bookingRoute);
app.use(paymentRoute);
app.use(driversRoute);
app.listen(port, () => {
console.log(`Server is running on PORT: ${port}`);
});
app.get("/", (req, res) => {
console.log(`GET / is Requested`);
res.status(200).json({
message: "ok",
});
});