-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
38 lines (29 loc) · 911 Bytes
/
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
require("rootpath")();
require("dotenv").config();
const jwt = require("./middleware/jwt");
const errorHandler = require("./middleware/error-handler");
const initialize = require("./init");
const users = require("./routes/auth");
const friendships = require("./routes/friendships");
const events = require("./routes/events");
const app = initialize();
// use JWT auth to secure the api
app.use(jwt());
// global error handler
app.use(errorHandler);
// api routes
app.use("/api/users", users);
app.use("/api/friendships", friendships);
app.use("/api/events", events);
// catch 404 and forward to error handler
app.use((req, res, next) => {
const err = new Error("Not Found");
err.status = 404;
next(err);
});
// start server
const port = process.env.NODE_ENV === "production" ? 80 : 5555;
app.listen(port, function () {
console.log("Server listening on port " + port);
});
module.exports = app;