Stuff and junk

This commit is contained in:
Kim Ravn Hansen
2025-09-02 19:10:25 +02:00
parent e12076260d
commit fc28f4ef55

View File

@@ -404,9 +404,18 @@ const server = http.createServer((req, res) => {
let filePath = path.join(__dirname, 'public', req.url === '/' ? 'index.html' : req.url); let filePath = path.join(__dirname, 'public', req.url === '/' ? 'index.html' : req.url);
const ext = path.extname(filePath); const ext = path.extname(filePath);
let contentType = 'text/html'; const contentTypes = {
if (ext === '.js') contentType = 'application/javascript'; '.js': 'application/javascript',
if (ext === '.css') contentType = 'text/css'; '.css': 'text/css',
'.html': 'text/html',
};
if (!contentType[ext]) {
// Invalid file, pretend it did not exist!
res.writeHead(404);
res.end('File not found');
return;
}
fs.readFile(filePath, (err, data) => { fs.readFile(filePath, (err, data) => {
if (err) { if (err) {