-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
37 lines (30 loc) · 1.12 KB
/
server.js
File metadata and controls
37 lines (30 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
/*************************/
/*** Configuration ***/
/*************************/
// Set your main file here
var mainFile = '/app/index.html';
// Set your available localhost port here
var localhostPort = 9050;
/*************************/
/*** End Configuration ***/
/*************************/
var express = require('express');
var dotenv = require('dotenv');
var jsonfile = require('jsonfile');
dotenv.load();
// Start the server
var localhost = express();
localhost.use(express.static(__dirname));
// Get the URL and redirect http to https in production environment else redirect to the main file
localhost.get(/.*/, function (req, res, next) {
// var env = process.env.NODE_ENV;
// res.json({environment: env});
if (req.headers['x-forwarded-proto'] !== 'https' && process.env.NODE_ENV === 'production')
res.redirect('https://'+ req.hostname + req.url);
else
// next() /* Continue to other routes if we're not redirecting */
res.sendFile(__dirname + mainFile);
});
localhost.listen(process.env.PORT || localhostPort, function () {
console.log("Start surfing at localhost:%d", localhostPort);
});