| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- const http = require('http');
- const fs = require('fs');
- const path = require('path');
- const PORT = 7777;
- const server = http.createServer((req, res) => {
- let filePath = req.url === '/' ? '/index.html' : req.url;
- filePath = path.join(__dirname, 'public', filePath);
- const extname = path.extname(filePath);
- const contentTypes = {
- '.html': 'text/html',
- '.css': 'text/css',
- '.js': 'application/javascript',
- '.json': 'application/json',
- '.png': 'image/png',
- '.jpg': 'image/jpeg',
- '.jpeg': 'image/jpeg',
- '.gif': 'image/gif',
- '.svg': 'image/svg+xml',
- '.ico': 'image/x-icon',
- };
- const contentType = contentTypes[extname] || 'text/plain';
- fs.readFile(filePath, (err, content) => {
- if (err) {
- if (err.code === 'ENOENT') {
- res.writeHead(404, { 'Content-Type': 'text/html' });
- res.end('<h1>404 - Página no encontrada</h1>', 'utf-8');
- } else {
- res.writeHead(500);
- res.end('Error interno del servidor');
- }
- } else {
- res.writeHead(200, { 'Content-Type': contentType });
- res.end(content, 'utf-8');
- }
- });
- });
- server.listen(PORT, () => {
- console.log(`Servidor del Festival Armadillos corriendo en http://localhost:${PORT}`);
- });
|