Skip to content

Commit

Permalink
refactor(http2): Prepare for server for http2
Browse files Browse the repository at this point in the history
  • Loading branch information
Yrkki committed Aug 9, 2020
1 parent 4a5a797 commit 583ab01
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 41 deletions.
31 changes: 8 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@
"npm-run-all": "4.1.5",
"rxjs": "^6.6.2",
"snyk": "1.370.1",
"spdy": "^4.0.2",
"tslib": "^2.0.1",
"tslint-angular": "3.0.2",
"zone.js": "^0.10.3"
Expand Down
64 changes: 46 additions & 18 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//Install new relic monitoring
require('newrelic');

//Install express server
// Configure port
const port = process.env.PORT || 5000

// Install express server
const express = require('express');
const app = express();
const compression = require('compression');
Expand All @@ -22,19 +25,19 @@ app.use(compression());

// Redirect http to https
app.get('*', function (req, res, next) {
if (req.headers['x-forwarded-proto'] !== 'https' &&
!(['true', 'TRUE'].includes(process.env.CV_GENERATOR_SKIP_REDIRECT_TO_HTTPS || '') ||
['localhost', '192.168.1.2', '192.168.1.6', '192.168.99.100'].includes(req.hostname))) {

var url = 'https://' + req.hostname;
// var port = app.get('port');
// if (port)
// url += ":" + port;
url += req.url;
res.redirect(url);
}
else
next();
if (req.headers['x-forwarded-proto'] !== 'https' &&
!(['true', 'TRUE'].includes(process.env.CV_GENERATOR_SKIP_REDIRECT_TO_HTTPS || '') ||
['localhost', '192.168.1.2', '192.168.1.6', '192.168.99.100'].includes(req.hostname))) {

var url = 'https://' + req.hostname;
// var port = app.get('port');
// if (port)
// url += ":" + port;
url += req.url;
res.redirect(url);
}
else
next();
});

// calc the root path
Expand All @@ -45,9 +48,34 @@ app.use(express.static(root));

// Configure Express Rewrites
app.all('/*', function (req, res, next) {
// Just send the index.html for other files to support HTML5Mode
res.sendFile('index.html', { root: root });
// Just send the index.html for other files to support HTML5Mode
res.sendFile('index.html', { root: root });
});

// Start the app by listening on the default Heroku port
app.listen(process.env.PORT || 5000);
function welcome(error) {
if (error) {
console.error(error)
return process.exit(1)
} else {
console.log('Listening on port: ' + port + '.')
}
}

// Start the app by listening on the default port
app.listen(port, welcome);

// // Install http/2
// const spdy = require('spdy')
// const fs = require('fs');

// // Prepare http/2 options
// const spdy_options = {
// // key: fs.readFileSync(__dirname + '/openssl.key'),
// // cert: fs.readFileSync(__dirname + '/openssl.crt')
// cert: fs.readFileSync(__dirname + '/cv-generator-fe.cer')
// }

// // Serve http/2
// spdy
// .createServer(spdy_options, app)
// .listen(port, welcome);

0 comments on commit 583ab01

Please sign in to comment.