-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
86 lines (74 loc) · 2.61 KB
/
server.js
File metadata and controls
86 lines (74 loc) · 2.61 KB
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
const express = require('express');
const session = require('express-session');
const path = require('path');
const bodyParser = require('body-parser');
const cors = require('cors');
const passport = require('passport');
var async = require('async');
var fs = require('fs');
var pg = require('pg');
// const config = require('./config.json')
// Connect to database.
const dbConfig = {
user: process.env.USER || require('./config.json').user,
password: process.env.PASSWORD || require('./config.json').password,
host: process.env.HOST || require('./config.json').host,
port: process.env.DBPORT || require('./config.json').port,
database: process.env.DATABASE || require('./config.json').database,
ssl: {
ca: fs.readFileSync(__dirname + '/trusty-lemur-ca.crt').toString(),
}
};
// Create a pool.
var pool = new pg.Pool(dbConfig);
const app = express();
// require('./services/passport')(passport);
app.use(
session({
name:'sid',
secret: 'Insert randomized text here',
resave: false,
saveUninitialized: false,
cookie: {
maxAge: 1000 * 60 * 60 * 2,
sameSite: true,
secure: true //process.env.NODE_ENV === 'production'
}
})
);
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cors());
// Enable reverse proxy support in Express. This causes the
// the "X-Forwarded-Proto" header field to be trusted so its
// value can be used to determine the protocol. See
// http://expressjs.com/api#app-settings for more details.
// app.enable('trust proxy');
// app.use(function (req, res, next) {
// if (req.secure || req.headers.host === 'localhost:5000') {
// next();
// } else {
// // request was via http, so redirect to https
// console.log('redirecting');
// console.log(req.headers.host);
// res.redirect(301, 'https://' + req.headers.host + req.url);
// }
// });
app.use(express.static(__dirname + '/client/build'));
app.use(passport.initialize());
// console.log('initialized');
app.use(passport.session());
require('./services/passport')(passport, pool);
require ('./routes/authenticateUsers')(app, passport, pool);
require ('./routes/queryStudent')(app, pool);
require ('./routes/queryCourses')(app, pool);
require ('./routes/queryTasks')(app, pool);
// All routes other than above will go to index.html
app.get('*', (req, res) => {
res.sendFile(__dirname + '/client/build/index.html');
});
/* Tell server to listen to port in environemnt variable, else, listen to port 5000 */
app.listen(process.env.PORT||5000, () => {
console.log('starting listening at port 5000');
});
// app.set('view engine', 'html');