Initial import

This commit is contained in:
2020-04-16 10:02:11 +02:00
commit 234bc3e264
10 changed files with 392 additions and 0 deletions

35
server.js Normal file
View File

@@ -0,0 +1,35 @@
var http = require('http');
var fileSystem = require('fs');
var server = http.createServer(function(req, resp){
var fileName = './index.html';
var contentType = 'text/html';
var path = req.url;
if (path) {
if (path.endsWith(".svg")) {
contentType = 'image/svg+xml';
} else if (path.endsWith(".css")) {
contentType = 'text/css';
}
if (path.endsWith(".svg") || path.endsWith(".css") || path.endsWith(".md") || path.endsWith(".ico")) {
fileName = "." + path;
}
}
console.log("request path:", path, " fileName:", fileName, " contentType:", contentType);
fileSystem.readFile(fileName, function(error, fileContent){
if(error){
resp.writeHead(500, {'Content-Type': 'text/plain'});
resp.end('Error');
}
else{
resp.writeHead(200, {'Content-Type': contentType});
resp.write(fileContent);
resp.end();
}
});
});
server.listen(8080);