-
Notifications
You must be signed in to change notification settings - Fork 9
/
server.js
51 lines (43 loc) · 1.49 KB
/
server.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
41
42
43
44
45
46
47
48
49
50
51
require("dotenv").config();
const express = require("express");
const server = express();
const morgan = require("morgan");
const fileupload = require("express-fileupload");
const cors = require("cors");
const helmet = require("helmet");
const chaptersRouter = require("./api/chapterRouter.js");
const reunionRouter = require("./api/reunionRouter");
const volunteerRouter = require("./api/volunteerRouter");
const userRouter = require("./api/userRouter.js");
const pendingRouter = require("./api/pendingRouter");
server.use(helmet());
server.use(cors());
server.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header(
"Access-Control-Allow-Headers",
"Origin,X-Requested-With,Content-Type,Accept,content-type,application/json"
);
res.header("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE,OPTIONS");
res.header("Access-Control-Allow-Credentials", true);
next();
});
server.use(logger);
server.use(morgan("dev"));
server.use(fileupload());
server.use(express.json());
server.get("/", (req, res) => {
res.status(200).json({ hello: "World!" });
});
server.use("/api/user", userRouter);
server.use("/api/chapter", chaptersRouter);
server.use("/api/reunion", reunionRouter);
server.use("/api/volunteer", volunteerRouter);
server.use("/api/pending", pendingRouter);
// custom logging function
function logger(req, res, next) {
const now = new Date().toISOString();
console.log(`A ${req.method} request to '${req.url}'at ${now}`);
next();
}
module.exports = server;