-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
93 lines (80 loc) · 2.31 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
const express = require('express');
const methodOverride = require('method-override');
const cookieParser = require('cookie-parser');
require('dotenv').config();
/**
* ===================================
* 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);
const format = require('pg-format');
var multer = require('multer');
var upload = multer({
dest: './uploads/',
});
var cloudinary = require('cloudinary');
var configForCloudinary;
if (process.env.CLOUDINARY_URL) {
configForCloudinary = process.env.CLOUDINARY_URL;
} else {
configForCloudinary = {
cloud_name: process.env.CLOUD_NAME,
api_key: process.env.API_KEY,
api_secret: process.env.API_SECRET,
};
}
cloudinary.config(configForCloudinary);
/**
* ===================================
* ===================================
* 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);