-
Notifications
You must be signed in to change notification settings - Fork 59
/
index.js
77 lines (58 loc) · 1.81 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const express = require('express');
const methodOverride = require('method-override');
const cookieParser = require('cookie-parser');
/**
* ===================================
* Configurations and set up
* ===================================
*/
// Init express app
const app = express();
// Set up middleware
app.use(methodOverride('_method'));
app.use(cookieParser());
app.use(express.static('public'));
app.use(express.json());
app.use(express.urlencoded({
extended: true
}));
// Set react-views to be the default view engine
const reactEngine = require('express-react-views').createEngine();
app.set('views', __dirname + '/views');
app.set('view engine', 'jsx');
app.engine('jsx', reactEngine);
/**
* ===================================
* ===================================
* DB
* ===================================
* ===================================
*/
// db contains *ALL* of our models
const allModels = require('./db');
/**
* ===================================
* ===================================
* Routes
* ===================================
* ===================================
*/
// get the thing that contains all the routes
const setRoutesFunction = require('./routes');
// call it and pass in the "app" so that we can set routes on it (also models)
setRoutesFunction(app, allModels);
/**
* ===================================
* Listen to requests on port 3000
* ===================================
*/
const PORT = process.env.PORT || 3000;
const server = app.listen(PORT, () => console.log('~~~ Tuning in to the waves of port '+PORT+' ~~~'));
let onClose = function(){
server.close(() => {
console.log('Process terminated')
allModels.pool.end( () => console.log('Shut down db connection pool'));
})
};
process.on('SIGTERM', onClose);
process.on('SIGINT', onClose);