commit initial

This commit is contained in:
2025-08-13 22:47:45 +03:00
commit 8d0eaf7af1
146 changed files with 19138 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
// server.js
const http = require('http');
const fs = require('fs');
const path = require('path');
const PORT = 3000;
const MIME_TYPES = {
'.html': 'text/html',
'.css': 'text/css',
'.js': 'text/javascript',
'.json': 'application/json',
'.xml': 'application/xml'
};
const server = http.createServer((req, res) => {
// Convert URL to file path, using index.html for root
let filePath = req.url === '/' ? './index.html' : '.' + req.url;
// Get file extension for MIME type
const ext = path.extname(filePath);
const contentType = MIME_TYPES[ext] || 'text/plain';
// Read and serve the file
fs.readFile(filePath, (err, content) => {
if (err) {
if (err.code === 'ENOENT') {
res.writeHead(404);
res.end('File not found');
} else {
res.writeHead(500);
res.end('Server error: ' + err.code);
}
} else {
res.writeHead(200, { 'Content-Type': contentType });
res.end(content);
}
});
});
server.listen(PORT, () => {
console.log(`Server running at http://localhost:${PORT}/`);
});