-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
48 lines (36 loc) · 996 Bytes
/
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
const express = require("express");
const bodyParser = require("body-parser");
const path = require("path");
const cookie = require("cookie-parser");
const morgan = require("morgan");
if (process.env.NODE_ENV !== 'production') {
require('dotenv').config();
}
const port = process.env.PORT || 5000;
const app = express();
app.use(bodyParser.json());
app.use(cookie());
app.use(morgan('dev'))
app.use(express.static(path.join("public")));
const users = require('./routes/users');
app.use(users);
const token = require('./routes/token');
app.use(token);
app.use((req, res) => {
res.sendStatus(404);
});
// Handle Boom errors
app.use((err, _req, res, _next) => {
console.log('boom error!')
if (err.output && err.output.statusCode) {
return res
.status(err.output.statusCode)
.set('Content-Type', 'text/plain')
.send(err.message);
}
console.error(err.stack);
res.sendStatus(500);
});
app.listen(port, () => {
console.log('listening on port', port)
})