From 053fbfd90bc89014c0c19920828f199e4150f3fb Mon Sep 17 00:00:00 2001 From: Raghu-Ch Date: Sun, 15 Jan 2017 23:13:34 -0800 Subject: [PATCH] Prep repo for Heroku --- package.json | 3 ++- server.js | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index e552968..44ca458 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "Simple react app", "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "start": "node server.js" }, "author": "Raghu", "license": "MIT", diff --git a/server.js b/server.js index 0158fea..1823406 100644 --- a/server.js +++ b/server.js @@ -2,9 +2,17 @@ var express = require('express'); // Create our app var app = express(); +const PORT = process.env.PORT || 3000; +app.use(function (req, res, next) { + if (req.headers['x-forwarded-proto'] === 'http') { + next(); + } else { + res.redirect('http://' + req.hostname + req.url); + } +}); app.use(express.static('public')); -app.listen(3000, function () { - console.log('Express server is up on port 3000'); +app.listen(PORT, function () { + console.log('Express server is up on port ' + PORT); });