Facilité maj site, ajouté rep "static"

- ajouté répertoire static, defaut pour aller chercher les fichiers
- ajouté sample_config.js, cf README
This commit is contained in:
Sylvain Gay 2022-09-12 13:49:35 +02:00
parent fa9f4f9f28
commit 445be5f7ff
8 changed files with 26 additions and 8 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
node_modules node_modules
package-lock.json package-lock.json
config.js

View file

@ -8,6 +8,13 @@ cd traque
npm install npm install
``` ```
## Configuration
```bash
cp -p sample_config.js config.js
```
Then edit manually `config.js`.
## Run server ## Run server
```bash ```bash

View file

@ -28,9 +28,9 @@
<script type="text/javascript"> <script type="text/javascript">
var protocol = "https"; var protocol = location.protocol;
var server = "localhost"; var server = location.hostname;
var port = "9000"; var port = location.port;
var socket = io.connect({rejectUnauthorized: false}, var socket = io.connect({rejectUnauthorized: false},
protocol+"://"+server+":"+port); protocol+"://"+server+":"+port);

7
sample_config.js Normal file
View file

@ -0,0 +1,7 @@
// Configuration file for the server
module.exports = {
"port": 9000,
"key": "certif/server.key",
"cert": "certif/server.crt"
}

View file

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

View file

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 6.1 KiB

View file

Before

Width:  |  Height:  |  Size: 590 B

After

Width:  |  Height:  |  Size: 590 B

View file

@ -23,18 +23,21 @@ var equipes = [];
var http = require('https');//require('http'); var http = require('https');//require('http');
var url = require('url'); var url = require('url');
var fs = require('fs'); var fs = require('fs');
var config = require('./config.js');
console.log("Setup http server"); console.log("Setup http server");
const option = { const option = {
key: fs.readFileSync('certif/server.key'), key: fs.readFileSync(config.key),
cert: fs.readFileSync('certif/server.crt') cert: fs.readFileSync(config.cert)
}; };
// The server // The server
var server = http.createServer(option, function(req, res){ var server = http.createServer(option, function(req, res){
var q = url.parse(req.url, true); var q = url.parse(req.url, true);
var filename = "." + q.pathname; var filename = "static" + q.pathname;
if(q.pathname.includes(".."))
filename = "static/dotdot.html";
if(q.pathname == "/") if(q.pathname == "/")
filename = "map.html"; filename = "map.html";
fs.readFile(filename, function(err, data) { fs.readFile(filename, function(err, data) {
@ -104,5 +107,5 @@ io.sockets.on('connection', function(socket){
}); });
console.log("Launch server"); console.log("Launch server");
server.listen(9000); server.listen(config.port, "::");
console.log("Running !"); console.log("Running !");