Cleanup of code, and redirect for http
parent
2b8947e0c1
commit
d9651b7d0f
|
|
@ -1,31 +1,43 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
"access-control-allow-origin": "*",
|
'access-control-allow-origin': '*',
|
||||||
"access-control-allow-methods": "GET, POST, PUT, DELETE, OPTIONS",
|
'access-control-allow-methods': 'GET, POST, PUT, DELETE, OPTIONS',
|
||||||
"access-control-allow-headers": "content-type, accept",
|
'access-control-allow-headers': 'content-type, accept',
|
||||||
"access-control-max-age": 10,
|
'access-control-max-age': 10,
|
||||||
"Content-Type": "application/json"
|
'Content-Type': 'application/json'
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.prepareResponse = function(req, cb) {
|
exports.prepareResponse = (req, cb) =>
|
||||||
var data = "";
|
{
|
||||||
req.on('data', function(chunk) { data += chunk; });
|
let data = '';
|
||||||
req.on('end', function() { cb(data); });
|
|
||||||
|
req.on('data', (chunk) =>
|
||||||
|
{
|
||||||
|
data += chunk;
|
||||||
|
});
|
||||||
|
|
||||||
|
req.on('end', () =>
|
||||||
|
{
|
||||||
|
cb(data);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.respond = function(res, data, status) {
|
exports.respond = (res, data, status) =>
|
||||||
status = status || 200;
|
{
|
||||||
res.writeHead(status, headers);
|
status = status || 200;
|
||||||
res.end(data);
|
res.writeHead(status, headers);
|
||||||
|
res.end(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.send404 = function(res) {
|
exports.send404 = (res) =>
|
||||||
exports.respond(res, 'Not Found', 404);
|
{
|
||||||
|
exports.respond(res, 'Not Found', 404);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.redirector = function(res, loc, status) {
|
exports.redirector = (res, loc, status) =>
|
||||||
status = status || 302;
|
{
|
||||||
res.writeHead(status, { Location: loc });
|
status = status || 302;
|
||||||
res.end();
|
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);
|
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);
|
const io = require('socket.io')(httpsServer);
|
||||||
|
|
||||||
// Handle connections from clients.
|
// Handle connections from clients.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue