-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
61 lines (45 loc) · 1.44 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
var bodyParser = require('body-parser');
var express = require('express');
const app = express();
const path = require('path');
const index = require('./server/router/index.js');
const sequelize_fixtures = require('sequelize-fixtures');
const models = require('./server/db/models');
const Payments = models.Payments;
const Chips = models.Chips;
const Users = models.User;
const Cards = models.cards;
const Log = models.log;
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
var session = require('express-session');
app.use(session({
secret: 'pokersecret',
resave: false
}));
app.use('/api', function (req, res, next) {
if (!req.session.counter) req.session.counter = 0;
console.log('counter', ++req.session.counter);
next();
});
app.set('view engine', 'html');
app.use('/', express.static(path.join(__dirname, './public')));
app.use('/api', index);
app.use('/*', function(req, res, next) {res.sendFile(path.resolve(__dirname, './public/index.html'))});
app.use(function (err, req, res, next){
console.error(err);
res.status(500).send(err.message)
});
Users.sync({})
.then(Cards.sync({})
.then(()=> Chips.sync({}))
.then(()=>Payments.sync({}))
.then(()=> Log.sync({}))
.then(sequelize_fixtures.loadFile('server/card_data.json', models))
.then(function () {
app.listen(3001, function () {
console.log('Server is listening on port 3001!');
});
})
);
module.exports = app;