-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
61 lines (46 loc) · 1.51 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
'use strict';
if(process.env.LOCAL !== true){
require('dotenv').load();
}
var express = require('express');
var routes = require('./app/routes/index.js');
var session = require('express-session');
var pg = require('pg');
var pgSession = require('connect-pg-simple')(session);
var parse = require('pg-connection-string').parse;
const fs = require('fs');
var http = require('http');
var passport = require('passport');
//postgresql config
var config = parse(process.env.DATABASE_URL);
config.ssl = true;
var app = express();
require('./app/config/passport')(passport);
app.use('/controllers', express.static(process.cwd() + '/app/controllers'));
app.use('/public', express.static(process.cwd() + '/public'));
app.use('/common', express.static(process.cwd() + '/app/common'));
var pgPool = new pg.Pool(config);
app.use(session({
store: new pgSession({
pool: pgPool, // Connection pool
tableName: 'session' // Use another table-name than the default "session" one
}),
secret: process.env.ZOO_COOKIE_SECRET,
resave: false,
cookie: { maxAge: 1* 24 * 60 * 60 * 1000 }, // 2 days
saveUninitialized: false
}));
app.use(passport.initialize());
app.use(passport.session());
routes(app, passport);
const server = http.createServer(app);
var port = '/tmp/nginx.socket';
/* if(process.env.LOCAL == true){
port = 8080;
}else{
port = '/tmp/nginx.socket';
} */
server.listen(port, function () {
console.log('Node.js listening on port ' + port + '...');
fs.closeSync(fs.openSync('/tmp/app-initialized', 'w'));
});