-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
41 lines (34 loc) · 954 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
import express from 'express';
import routes from './routes';
import bodyParser from "body-parser";
import config from "config";
import dbContext from "sequelize-context";
import prettyError from "pretty-error";
import process from "process";
import errorHandler from "errorhandler";
import notFoundHandler from "./middleware/notFoundHandler";
dbContext.connect(config.database, config.username, config.password, {
logging: false,
dialect: config.dialect
});
const app = express();
app.use(bodyParser.json());
app.use(routes);
app.use(errorHandler());
app.use(notFoundHandler);
app.disable('etag');
app.use(function(err, req, res, next) {
if (err.isBoom) {
res
.status(400)
.json(err.data);
}
next();
});
// do not listen if the server was started by the test
// runner, otherwise you'll get "port in use" errors.
const testing = process.env.NODE_ENV === "test";
if (!testing) {
app.listen(8080);
}
export default app;