Cleanup of code, and redirect for http
parent
2b8947e0c1
commit
d9651b7d0f
|
|
@ -1,31 +1,43 @@
|
|||
'use strict';
|
||||
|
||||
const headers = {
|
||||
"access-control-allow-origin": "*",
|
||||
"access-control-allow-methods": "GET, POST, PUT, DELETE, OPTIONS",
|
||||
"access-control-allow-headers": "content-type, accept",
|
||||
"access-control-max-age": 10,
|
||||
"Content-Type": "application/json"
|
||||
'access-control-allow-origin': '*',
|
||||
'access-control-allow-methods': 'GET, POST, PUT, DELETE, OPTIONS',
|
||||
'access-control-allow-headers': 'content-type, accept',
|
||||
'access-control-max-age': 10,
|
||||
'Content-Type': 'application/json'
|
||||
};
|
||||
|
||||
exports.prepareResponse = function(req, cb) {
|
||||
var data = "";
|
||||
req.on('data', function(chunk) { data += chunk; });
|
||||
req.on('end', function() { cb(data); });
|
||||
exports.prepareResponse = (req, cb) =>
|
||||
{
|
||||
let data = '';
|
||||
|
||||
req.on('data', (chunk) =>
|
||||
{
|
||||
data += chunk;
|
||||
});
|
||||
|
||||
req.on('end', () =>
|
||||
{
|
||||
cb(data);
|
||||
});
|
||||
};
|
||||
|
||||
exports.respond = function(res, data, status) {
|
||||
status = status || 200;
|
||||
res.writeHead(status, headers);
|
||||
res.end(data);
|
||||
exports.respond = (res, data, status) =>
|
||||
{
|
||||
status = status || 200;
|
||||
res.writeHead(status, headers);
|
||||
res.end(data);
|
||||
};
|
||||
|
||||
exports.send404 = function(res) {
|
||||
exports.respond(res, 'Not Found', 404);
|
||||
exports.send404 = (res) =>
|
||||
{
|
||||
exports.respond(res, 'Not Found', 404);
|
||||
};
|
||||
|
||||
exports.redirector = function(res, loc, status) {
|
||||
status = status || 302;
|
||||
res.writeHead(status, { Location: loc });
|
||||
res.end();
|
||||
exports.redirector = (res, loc, status) =>
|
||||
{
|
||||
status = status || 302;
|
||||
res.writeHead(status, { Location: loc });
|
||||
res.end();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -97,6 +97,19 @@ httpsServer.listen(config.listeningPort, '0.0.0.0', () =>
|
|||
logger.info('Server running on port: ', config.listeningPort);
|
||||
});
|
||||
|
||||
const httpServer = app.createServer();
|
||||
|
||||
// set up a route to redirect http to https
|
||||
http.get('*', (req, res) =>
|
||||
{
|
||||
res.redirect('https://' + req.headers.host + req.url);
|
||||
})
|
||||
|
||||
httpServer.listen(config.listeningRedirectPort, '0.0.0.0', () =>
|
||||
{
|
||||
logger.info('Server redirecting port: ', config.listeningRedirectPort);
|
||||
});
|
||||
|
||||
const io = require('socket.io')(httpsServer);
|
||||
|
||||
// Handle connections from clients.
|
||||
|
|
|
|||
Loading…
Reference in New Issue