/
server.js
66 lines (50 loc) · 1.3 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
var express = require('express');
var app = express();
var path = require('path');
var fs = require('fs');
app.use(express.static(path.resolve(__dirname+'/dist')));
var port = 9910;
app.listen(process.env.PORT || port, () => {
console.log("Server started at port " + port);
});
app.get('/*', (req, res) => {
var index = path.resolve(__dirname+'/dist/index.html');
console.log(index);
var bools = false;
(function() {
fs.stat(index, function (err, stats) {
if (stats.isFile) {
bools = true;
console.log('this is bools: ' + bools);
}
});
})();
// res.send('here we are');
res.sendFile(index);
})
// If an incoming request uses
// a protocol other than HTTPS,
// redirect that request to the
// same url but with HTTPS
/* const forceSSL = function() {
return function (req, res, next) {
if (req.headers['x-forwarded-proto'] !== 'https') {
return res.redirect(
['https://', req.get('Host'), req.url].join('')
);
}
next();
}
}
// Instruct the app
// to use the forceSSL
// middleware
app.use(forceSSL()); */
/*
should be added to package.json
then run
npm deploy
"scripts": {
// ...
"deploy": "git push origin master && git push heroku master"
}, */