Aggiungi documentazione: requisiti, implementazione, lezioni apprese
This commit is contained in:
1 parent
d1fd88b5ff
commit
de45b6c3b0
6 files changed
+500
-210
No files matched your search
+20
@@ -0,0 +1,20 @@
|
||||
const http = require('http');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const PORT = 8095;
|
||||
const ROOT = '/home/codex/giochino';
|
||||
|
||||
const MIME = { '.html': 'text/html', '.js': 'application/javascript', '.css': 'text/css', '.png': 'image/png' };
|
||||
|
||||
const server = http.createServer((req, res) => {
|
||||
let filePath = path.join(ROOT, req.url === '/' ? 'index.html' : req.url);
|
||||
const ext = path.extname(filePath);
|
||||
fs.readFile(filePath, (err, data) => {
|
||||
if (err) { res.writeHead(404); res.end('404'); return; }
|
||||
res.writeHead(200, { 'Content-Type': MIME[ext] || 'text/plain' });
|
||||
res.end(data);
|
||||
});
|
||||
});
|
||||
|
||||
server.listen(PORT, '0.0.0.0', () => console.log(`Server: http://0.0.0.0:${PORT}/`));
|
||||
Reference in new issue
Block a user