-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
42 lines (31 loc) · 1023 Bytes
/
Copy pathapp.js
File metadata and controls
42 lines (31 loc) · 1023 Bytes
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
const path = require("path");
const express = require("express");
const crewRoutes = require("./routes/crewRoutes");
const connectionRoutes = require("./routes/connectionRoutes");
const { errorHandler, notFoundHandler } = require("./utils/errors");
const app = express();
app.use((req, res, next) => {
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Access-Control-Allow-Methods", "GET,POST,PUT,PATCH,DELETE,OPTIONS");
res.setHeader("Access-Control-Allow-Headers", "Content-Type");
if (req.method === "OPTIONS") {
return res.sendStatus(204);
}
next();
});
app.use(express.json());
app.use(express.static(path.join(__dirname), { index: false }));
app.get("/", (_req, res) => {
res.sendFile(path.join(__dirname, "index.html"));
});
app.get("/health", (_req, res) => {
res.json({
name: "CrewGraph API",
status: "ok"
});
});
app.use("/connection", connectionRoutes);
app.use("/crew", crewRoutes);
app.use(notFoundHandler);
app.use(errorHandler);
module.exports = app;