forked from SAP-archive/yaas-storefront
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
52 lines (40 loc) · 1.27 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
/**
* [y] hybris Platform
*
* Copyright (c) 2000-2015 hybris AG
* All rights reserved.
*
* This software is the confidential and proprietary information of hybris
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the
* license agreement you entered into with hybris.
*/
'use strict';
// ExpressJS configuration for single tenant
var express = require('express');
// Build the server
var app = express();
app.set('trust proxy', true); //for https redirect
var httpsRedirect = function (req, res, next) {
var host = req.get('host');
if (req.host === 'localhost') {
next();
}
else {
console.log('HTTPS REDIRECT: ', req.protocol);
if ('https' === req.protocol) {
next();
} else {
//redirect to https based url provided by ELB
console.log('INSECURE REDIRECTING TO: ' + 'https://' + host + req.url);
return res.redirect(301, 'https://' + host + req.url); //Infinite loop.
}
}
};
var useHttps = /*StartUseHTTPS*/ false /*EndUseHTTPS*/;
if (useHttps) {
app.use(httpsRedirect);
}
// map access to public files
app.use(express.static(__dirname + '/public'));
module.exports = app;