-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
58 lines (42 loc) · 1.44 KB
/
server.js
File metadata and controls
58 lines (42 loc) · 1.44 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
58
// IMPORTS ------------------------------------------
import express from 'express';
import cors from 'cors';
import './db-connect.js';
import usersRouter from "./routes/usersRouter.js";
import groupsRouter from "./routes/groupsRouter.js";
import eventsRouter from "./routes/eventsRouter.js";
import tasksRouter from "./routes/tasksRouter.js";
// --------------------------------------------------
// SETUPS -------------------------------------------
const app = express();
// --------------------------------------------------
// MIDDLEWARE ---------------------------------------
app.use(express.json());
app.use(cors({ origin: "http://localhost:19006", credentials: true }));
// --------------------------------------------------
// ROUTES -------------------------------------------
app.get("/", (req, res) => {
res.send("<h1>FlatMates API</h1>");
});
app.use("/users", usersRouter);
app.use("/groups", groupsRouter);
app.use("/events", eventsRouter);
app.use("/tasks", tasksRouter);
// --------------------------------------------------
const port = 7;
app.listen(port, () => {
console.log(`App listening at http://localhost:${port}`);
});
// ERROR HANDLER ------------------------------------
app.use(
function errorHandler (err, req, res, next) {
res.status(err.status || 400)
.send({
error: {
message: err.message,
status: err.status
}
})
}
);
// --------------------------------------------------