forked from NVComputing/nvcomputingsite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (29 loc) · 1.12 KB
/
Copy pathindex.js
File metadata and controls
39 lines (29 loc) · 1.12 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
#!/usr/bin/nodejs
console.log('Loading libraries...');
let express = require('express');
let app = express();
let routes = require('./routes');
console.log('Setting redirect functions...');
app.use(function forceDomain(req, res, next) {
// Don't allow user to hit Heroku, www-version of site, or http version of site
let host = req.hostname;
let env = process.env.NODE_ENV;
if (host === 'nvcomputing.herokuapp.com' || req.headers.host.slice(0, 4) === 'www.' ||
(req.protocol !== 'https' && env === "production")) {
return res.redirect(301, 'https://nvcomputing.com' + req.originalUrl);
}
next();
});
app.set('port', process.env.PORT || 8080);
app.set('trust proxy', true);
console.log('Setting /static/ directory as static file root...');
app.use(express.static('static'));
console.log('Registering router endpoints...');
routes.set(app);
app.set('views', './views');
app.set('view engine', 'hbs');
let listener = app.listen(app.get('port'), function () {
console.log('Express server started.');
console.log('--------------------------');
console.log('Website is now live at http://localhost:' + listener.address().port);
});