-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
38 lines (30 loc) · 892 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
const express = require('express');
const morgan = require('morgan');
const helmet = require('helmet');
const cors = require('cors');
const bodyParser = require('body-parser');
const addPlanRoutes = require('./routes/plan');
class Server {
constructor({ port }) {
if (!port) {
throw new Error('Server must be given port in initializer');
}
this.port = port;
}
start(done) {
const app = express();
app.use(morgan('combined'));
app.use(cors());
app.use(helmet());
app.use(bodyParser.urlencoded({ extended: true }));
addPlanRoutes(app);
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).send('Something went wrong!');
});
app.listen(this.port, () => {
done();
});
}
}
module.exports = Server;