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.
24 lines
607 B
24 lines
607 B
const fs = require('fs'),
|
|
config = require('./config');
|
|
http = require('http');
|
|
|
|
|
|
console.log("Starting static server on port "+config.STATIC_PORT);
|
|
|
|
http.createServer((req, res) => {
|
|
let url = req.url;
|
|
if(!req.url || req.url == "" || req.url == "/") url = "/index.html";
|
|
fs.readFile(config.STATIC_LOCATION + url, (err, data) => {
|
|
if(err) {
|
|
console.log("Failed to retreive requested url '"+url+"': "+err);
|
|
res.writeHead(404);
|
|
res.end(JSON.stringify(err));
|
|
return;
|
|
} else {
|
|
console.log("Writing "+url);
|
|
res.writeHead(200);
|
|
res.end(data);
|
|
}
|
|
});
|
|
}).listen(config.STATIC_PORT);
|