-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
71 lines (57 loc) · 2.11 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
68
69
70
71
if (process.env.NODE_ENV !== 'production') {
require('dotenv').load();
}
var sslRedirect = require('heroku-ssl-redirect');
var express = require('express');
var session = require('express-session');
var cookieParser = require('cookie-parser')
var PostgreSqlStore = require('connect-pg-simple')(session);
var app = express();
const bodyParser = require('body-parser');
// Enable SSL redirect
app.use(sslRedirect(['production'], 301));
app.use(express.static(__dirname + '/public'));
app.set('port', (process.env.PORT || 5000));
// views is directory for all template files
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
var db_url = process.env.DATABASE_URL || "postgres://postgres:killerfly@localhost:5432/postgres";
const conObject = {
user: process.env.DATABASE_USER || "postgres",
password: process.env.DATABASE_PASS || "killerfly",
database: process.env.DATABASE_DB || "postgres",
port: 5432,
host: process.env.DATABASE_HOST || "localhost",
ssl: true
}
app.use(session({
secret: process.env.SECRET || 'fadb4443e5d14fe6f7d04637f78077c75c73d1b4',
proxy: true,
resave: true,
saveUninitialized: true,
store: new PostgreSqlStore({
conObject: conObject,
}),
})
);
// Postgres for session table
// CREATE TABLE "session" ("sid" varchar NOT NULL COLLATE "default", "sess" json NOT NULL, "expire" timestamp(6) NOT NULL) WITH (OIDS=FALSE);
// ALTER TABLE "session" ADD CONSTRAINT "session_pkey" PRIMARY KEY ("sid") NOT DEFERRABLE INITIALLY IMMEDIATE;
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
app.use(cookieParser())
var normalizedPath = require("path").join(__dirname, "app/routes");
require("fs").readdirSync(normalizedPath).forEach(function(file) {
require("./app/routes/" + file)(app);
});
var ATM = require('./app/modules/account-manager');
ATM.createAdmin(process.env.ADMIN_PASS);
var ANM = require('./app/modules/accreditation-manager');
ANM.createHR();
var NHM = require('./app/modules/new-hire-manager.js');
NHM.createOwners();
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});