You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.2 KiB

const http = require('http');
const url = require('url');
const fs = require('fs');
var config=null;
//if config.local.jsoon exists load it
if(fs.existsSync(process.cwd() + '/config.local.json')){
config = require(process.cwd() + '/config.local.json');
}
// else load normal config file
else {
config = require(process.cwd() + '/config.json');
}
function outputHTML5(status, response, content, title)
{
response.writeHead(status, { 'Content-Type': 'text/html; charset=utf-8' });
response.write(
`
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>${title}</title>
<style type="text/css">*{ font-family: sans-serif }</style>
</head>
<body>
${content}
</body>
</html>
`
);
response.end();
}
//par defaut on se considère
let env = 'install';
var server = http.createServer(function (request, response) {
if(request.url === "/") {
startup_args = process.argv.slice(2);
content = config[startup_args[0]].config_id;
outputHTML5(200,response,content,"Server info");
}
else {
outputHTML5(404,response,'Y\'a rien ici',"Oups");
}
});
server.listen(80);