-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
51 lines (43 loc) · 1.43 KB
/
server.js
File metadata and controls
51 lines (43 loc) · 1.43 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
import express from "express";
import { mongoStart, client } from "./mongo/connect.js"
import { router as authRouter } from "./router/auth.js"
import { router as productRouter } from "./router/product.js"
import { router as orderRouter } from "./router/order.js"
import session from "express-session"
import cookieParser from "cookie-parser"
import Fileupload from "express-fileupload"
import cors from "cors"
const app = express();
const PORT = 3000;
app.use(cors({
origin: "http://localhost:8100",
methods: "POST,GET,PUT,DELETE",
credentials: true
}))
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(session({secret:"key",cookie:{maxAge:600000}}));
app.use(Fileupload())
app.get("/", (req, res) => {
res.send("Hello from Express!");
});
app.use("/api/product/", productRouter)
app.use("/api/order/", orderRouter)
app.use("/api/auth/", authRouter)
mongoStart().catch(console.dir);
var server = app.listen(PORT, () => {
console.log(`Express server running at http://localhost:${PORT}/`);
});
const gracefulShutdown = async () => {
console.log("Shutting down server...");
await client.close();
server.close(() => {
console.log("Express server stopped.");
process.exit(0);
});
};
// Handle shutdown signals
process.on("SIGINT", gracefulShutdown); // Ctrl+C
process.on("SIGTERM", gracefulShutdown); // Termination signal
process.on("exit", gracefulShutdown); // On process