diff --git a/sample_config.js b/sample_config.js index eec7ba3..05a20e7 100644 --- a/sample_config.js +++ b/sample_config.js @@ -12,11 +12,12 @@ function validator(id){ module.exports = { "port": 9000, + "http_port": 9001, "key": "certif/server.key", "cert": "certif/server.crt", - "validator": validator, + "validator": validator, - // Offset for the randomization of the blurred status - "lat_ofs": 0.0005, - "long_ofs": 0.0005, + // Offset for the randomization of the blurred status + "lat_ofs": 0.0005, + "long_ofs": 0.0005, } diff --git a/traque.js b/traque.js index 2fa1de5..f714a9b 100644 --- a/traque.js +++ b/traque.js @@ -27,7 +27,8 @@ Les messages à transmettre par le serveur : */ // require = include -var http = require('https');//require('http'); +var https = require('https'); +var http = require('http'); var url = require('url'); var fs = require('fs'); var config = require('./config.js'); @@ -44,7 +45,7 @@ const bonus_delay = 10000;// 3*60*1000; var equipes = {}; -console.log("Setup http server"); +console.log("Setup https server"); const option = { key: fs.readFileSync(config.key), @@ -52,7 +53,7 @@ const option = { }; // The server -var server = http.createServer(option, function(req, res){ +var server = https.createServer(option, function(req, res){ var q = url.parse(req.url, true); var filename = "static" + q.pathname; if(q.pathname.includes("..")) @@ -110,6 +111,14 @@ var server = http.createServer(option, function(req, res){ }); }); +console.log("Setup http redirection"); +//HTTP -> HTTPS redirect +var redirect_server = http.createServer(function(req, res){ + var url = `https://${req.headers.host.split(":")[0]}:${config.port}${req.url}`; + res.writeHead(301,{Location: url}); + res.end(); +}); + console.log("Setup io server"); const { Server } = require("socket.io"); var io = new Server(server); @@ -370,4 +379,5 @@ io.on('connection', function(socket){ console.log("Launch server"); server.listen(config.port, "::"); +redirect_server.listen(config.http_port, "::"); console.log("Running !");