-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
55 lines (40 loc) · 1.18 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const express = require('express');
const mysql = require('mysql2');
const db = require('./models');
const bodyParser = require('body-parser');
const cors = require('cors');
const cookieParser = require("cookie-parser");
class App {
constructor () {
console.log("app.js");
this.app = express();
this.dbConnection();
this.setMiddleWare();
this.getRouting();
}
dbConnection() {
// db.sequelize.sync({force: true})
db.sequelize.sync()
// db.sequelize.authenticate()
.then(() => {
console.log('Connection has been established successfully.');
})
.then(() => {
console.log('DB sync complete.')
})
.catch(err => {
console.log("Unable to connect to the database: ", err);
});
}
setMiddleWare() {
this.app.use(express.json());
this.app.use(bodyParser.json());
this.app.use(bodyParser.urlencoded({ extended: false }));
this.app.use(cors());
this.app.use(cookieParser());
}
getRouting() {
this.app.use(require('./controllers'));
}
}
module.exports = new App().app;