-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
53 lines (43 loc) · 1.23 KB
/
index.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
49
50
51
52
53
const express = require('express');
const bodyParser = require('body-parser');
const morgan = require("morgan");
const errorhandler = require('errorhandler');
const config = require("./config")
const dbConnection = require("./models").dbConnection;
var isProduction = config.stage;
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(morgan('combined'))
dbConnection.sequelize.authenticate()
.then(() => {
console.log("Connection has been established successfully.")
dbConnection.sequelize.sync({ force: true }).then(() => {
console.log("Synced db with drop.");
});
})
.catch(err => {
console.error("Unable to connect to the database:", err)
});
app.use('/api', require('./routes'));
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
if (!isProduction) {
app.use(errorhandler())
}
/// error handlers
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.json(
{
"error":{
message: err.message
}
});
});
app.listen(config.port, () => {
console.log('ExpressSequelizePassport started on port: ' + config.port)
});