-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
57 lines (49 loc) · 1.54 KB
/
app.js
File metadata and controls
57 lines (49 loc) · 1.54 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
52
53
54
55
56
57
require("dotenv").config();
require("./database/mongodb");
const handlers = require("./routes/handlers");
const {
getAllEvents,
findSession,
getEventWithSessionInfo,
} = require("./routes/readData");
const {
createNewEvent,
deleteEvent,
createNewSession,
addSessionToEvent,
addNewParticipant,
updateResults,
} = require("./routes/writeData");
const port = process.env.PORT || 8080;
const express = require("express");
var cors = require("cors");
const app = express();
app.use(express.json());
app.use(cors());
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept, Authorization"
);
res.header("Access-Control-Allow-Methods", "PUT, POST, GET, DELETE, OPTIONS");
next();
});
// app.use(handlers.notFound);
app.use(handlers.internalServerError);
app.get("/events/getall", getAllEvents);
app.get("/sessions/:id", findSession);
app.get("/events/event_sessions/:id", getEventWithSessionInfo);
app.post("/events/create_new", createNewEvent);
app.post("/sessions/create_new", createNewSession);
app.post("/participants/create_new", addNewParticipant);
app.post("/sessions/update_results", updateResults);
app.delete("/events/delete/:id", deleteEvent);
app.listen(port, () =>
process.env.ENV == "LOCAL"
? console.log(
`The server is now running on http://localhost:${port}. ` +
`Press Ctrl + C to terminate.`
)
: console.log(`The server is now running in ${process.env.ENV} environment`)
);