-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
38 lines (31 loc) · 1.03 KB
/
app.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
import express from "express";
import cors from "cors";
import cookieParser from "cookie-parser";
import { config } from "dotenv";
import { error } from "./middlewares/errorHandler.js";
import userRouter from "./routes/users.js";
import articleRouter from "./routes/articles.js";
import volumeRouter from "./routes/volumes.js";
import announcementRouter from "./routes/announcements.js";
export const app = express();
//specify path to env variables
config({ path: "./configs/config.env" });
//Middlewares
const corsOptions = {
origin: process.env.FRONTEND_URL,
methods: ["GET", "HEAD", "PUT", "PATCH", "POST", "DELETE"],
credentials: true,
};
app.use(cors(corsOptions));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
app.use("/api/v1/users", userRouter);
app.use("/api/v1/articles", articleRouter);
app.use("/api/v1/volumes", volumeRouter);
app.use("/api/v1/announcements", announcementRouter);
app.get("/", (req, res) => {
res.send("working");
});
//Error Middleware
app.use(error);