added a http redirection to https
This commit is contained in:
parent
f231daf4e9
commit
26b28fad3e
2 changed files with 18 additions and 7 deletions
|
@ -12,6 +12,7 @@ function validator(id){
|
|||
|
||||
module.exports = {
|
||||
"port": 9000,
|
||||
"http_port": 9001,
|
||||
"key": "certif/server.key",
|
||||
"cert": "certif/server.crt",
|
||||
"validator": validator,
|
||||
|
|
16
traque.js
16
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 !");
|
||||
|
|
Loading…
Reference in a new issue