-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (33 loc) · 1.11 KB
/
index.js
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
import Env from "./config.js";
import "dotenv/config";
import express from "express";
import cookieParser from "cookie-parser";
import { router as authRouter } from "./routes/authRoutes.js";
import { router as uploadRouer } from "./routes/uploadRoutes.js";
import { useAuth } from "./middlewares/authMiddleare.js";
import { upload } from "./middlewares/uploadMiddleware.js";
import cors from "cors";
import logger, { useLogger } from "./utils/logger.js";
const allowedOrigins = ["http://localhost:6969"];
const corsOptions = {
origin: allowedOrigins,
methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
credentials: true,
optionsSuccessStatus: 202,
};
const app = express();
app.use(useLogger);
app.use(cors(corsOptions));
app.use(cookieParser());
app.use(express.json());
app.use("/auth", authRouter);
app.use("/upload", useAuth, upload.single("file"), uploadRouer);
app.get("/health", (req, res) => {
res.send("ok\n");
});
app.listen(parseInt(Env.PORT), () => {
logger.info(`Running on port ${Env.PORT}..`);
});
process.on("SIGTERM", () => {
logger.info(`[INFO] Stopping the server running on port ${Env.PORT}...`);
});