-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
67 lines (50 loc) · 1.64 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
56
57
58
59
60
61
62
63
64
65
66
67
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
// const { sequelize } = require('./models')
// db 관련
const db = require('./models');
class App {
constructor () {
this.app = express();
this.dbConnection();
this.setMiddleWare();
// this.getRouting();
}
dbConnection() {
// db.sequelize.sync({force: true})
db.sequelize.authenticate()
.then(() => {
console.log('Connection has been established successfully.');
})
.then(() => {
console.log('DB Sync complete.');
// we're not syncing; instead we're authenticating and using sequelize migration
// return db.sequelize.sync({force: true});
})
.catch(err => {
console.error('Unable to connect to the database:', err);
});
}
getRouting (){
this.app.use(require('./controllers'));
}
setMiddleWare (){
// 미들웨어 셋팅
this.app.use(express.json());
this.app.use(bodyParser.json());
this.app.use(bodyParser.urlencoded({ extended: false }));
this.app.use(cors());
}
}
module.exports = new App().app;
// const app = express()
// app.use(express.json())
// app.use(require('./controllers'))
// app.listen( {port : 5000}, async () => {
// console.log('Server up on localhost port 5000')
// // syncing sequelize
// // sequelize.sync({ force : true }) is exactly the same as sequelize.authenticate()
// await sequelize.authenticate()
// console.log('Database authenticated!')
// })