-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathrogue-web-server.js
72 lines (61 loc) · 2.81 KB
/
rogue-web-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
67
68
69
70
71
72
/*****************************************************************************
* Project: ShipFast API Protection (Server)
* File: rogue-web-server.js
* Original: Created on 6 Oct 2017 by Simon Rigg
* Copyright(c) 2002 - 2017 by CriticalBlue Ltd.
*
* The rogue ShipFast 'ShipRaider' web server.
*****************************************************************************/
const express = require('express')
const app = express()
const cors = require('cors')
const https = require('https')
const fs = require('fs')
const config = require('./demo-configuration').config
const chalk = require('chalk')
// Auto detection of colour support does not work always, thus we need to
// enforce it to support 256 colors.
const ctx = new chalk.Instance({level: 2})
const info = ctx.bold.blue
app.use(express.static('public'))
app.use(cors())
app.options('*', cors())
app.set('view engine', 'ejs')
app.set('views', './views')
app.get('/', function(req, res) {
res.render('pages/index', {
CURRENT_DEMO_STAGE_NAME: config.CURRENT_DEMO_STAGE_NAME,
BOOTSTRAP_COLOR_CLASS: config.BOOTSTRAP_COLOR_CLASS,
SHIPFAST_API_BASE_URL: config.SHIPFAST_PUBLIC_DOMAIN_HTTP_PROTOCOL + "://" + config.SHIPFAST_PUBLIC_DOMAIN,
SHIPFAST_API_DEMO_STAGE_URL: config.SHIPFAST_PUBLIC_DOMAIN_HTTP_PROTOCOL + "://" + config.SHIPFAST_PUBLIC_DOMAIN + "/" + config.SHIPFAST_API_VERSION,
SHIPFAST_API_VERSION: config.SHIPFAST_API_VERSION,
DEMO_STAGES: config.DEMO_STAGES,
CURRENT_DEMO_STAGE: config.CURRENT_DEMO_STAGE,
API_KEY: config.SHIPFAST_API_KEY,
DRIVER_LATITUDE: config.DRIVER_LATITUDE,
DRIVER_LONGITUDE: config.DRIVER_LONGITUDE,
AUTH0_DOMAIN: config.AUTH0_DOMAIN,
AUTH0_CLIENT_ID: config.AUTH0_CLIENT_ID,
HMAC_SECRET: config.SHIPFAST_API_HMAC_SECRET
})
})
if (config.SHIPRAIDER_HTTP_PROTOCOL === "https") {
console.log("Host Name: " + config.SHIPRAIDER_SERVER_HOSTNAME)
// Load the certificatie and key data for our server to be hosted over HTTPS
let serverOptions = {
key: fs.readFileSync(config.NODE_SSL_DIR + config.SHIPRAIDER_SERVER_HOSTNAME + ".key"),
cert: fs.readFileSync(config.NODE_SSL_DIR + config.SHIPRAIDER_SERVER_HOSTNAME + ".pem"),
requestCert: false,
rejectUnauthorized: false
}
// Create and run the HTTPS server
https.createServer(serverOptions, app).listen(HTTPS_PORT, function() {
const URL = config.SHIPRAIDER_HTTP_PROTOCOL + '://' + config.SHIPRAIDER_SERVER_HOSTNAME + ":" + config.SHIPRAIDER_HTTPS_PORT
console.log(info("\nSecure ShipRaider Rogue Web server listening on " + URL + "\n"))
})
} else {
app.listen(config.SHIPRAIDER_HTTP_PORT, function () {
const URL = config.SHIPRAIDER_HTTP_PROTOCOL + '://' + config.SHIPRAIDER_SERVER_HOSTNAME + ":" + config.SHIPRAIDER_HTTP_PORT
console.log(info("\nShipRaider server ready on " + URL + "\n"))
})
}