-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
67 lines (60 loc) · 1.58 KB
/
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
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
/* =======================
LOAD THE DEPENDENCIES
==========================*/
const express = require('express');
const bodyParser = require('body-parser');
const morgan = require('morgan');
const Sequelize = require('sequelize');
const syncDatabase = require('./bin/sync-db');
/* =======================
LOAD THE CONFIG
==========================*/
const config = require('./config');
const port = process.env.PORT || 3000
/* =======================
EXPRESS CONFIGURATION
==========================*/
const app = express()
// parse JSON and url-encoded query
app.use(bodyParser.urlencoded({extended: false}))
app.use(bodyParser.json())
// print the request log on console
app.use(morgan('dev'))
// set the secret key variable for jwt
app.set('jwt-secret', config.secret)
// index page, just for testing
app.get('/', (req, res) => {
res.send('Hello JWT')
})
// configure api router
app.use('/api', require('./routes/api'))
// open the server
app.listen(port, () => {
console.log(`Express is running on port ${port}`)
})
/* =======================
DB SEQUELIZE CONFIGURATION
==========================*/
const sequelize = new Sequelize(config.database, config.user, config.password, {
host: 'localhost',
dialect: 'mysql',
pool: {
max: 5,
min: 0,
idle: 10000
}
});
sequelize
.authenticate()
.then(() => {
console.log('Connection has been established successfully.');
})
.catch(err => {
console.error('Unable to connect to the database:', err);
});
module.exports = {
sequelize: sequelize
}
// syncDatabase().then(() => {
// console.log('Database sync');
// });