Spaces:
Running
Running
| 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', | |
| '.png': 'image/png', | |
| '.jpg': 'image/jpeg', | |
| '.wav': 'audio/wav', | |
| '.mp4': 'video/mp4', | |
| '.webm': 'video/webm' | |
| }; | |
| const server = http.createServer((req, res) => { | |
| // Decode URL in case of encoded characters | |
| const decodedUrl = decodeURIComponent(req.url); | |
| let filePath = path.join(__dirname, decodedUrl === '/' ? 'index.html' : decodedUrl); | |
| const ext = path.extname(filePath).toLowerCase(); | |
| const contentType = MIME_TYPES[ext] || 'application/octet-stream'; | |
| fs.readFile(filePath, (err, data) => { | |
| if (err) { | |
| if (err.code === 'ENOENT') { | |
| res.writeHead(404, { 'Content-Type': 'text/plain; charset=utf-8' }); | |
| res.end('ไม่พบไฟล์ที่ต้องการ (404 Not Found)'); | |
| } else { | |
| res.writeHead(500, { 'Content-Type': 'text/plain; charset=utf-8' }); | |
| res.end(`ข้อผิดพลาดภายในเซิร์ฟเวอร์: ${err.code}`); | |
| } | |
| } else { | |
| res.writeHead(200, { 'Content-Type': contentType }); | |
| res.end(data); | |
| } | |
| }); | |
| }); | |
| server.listen(PORT, () => { | |
| console.log(`=========================================`); | |
| console.log(`🌀 Typhoon Video Transcriber Server Started`); | |
| console.log(`👉 Open in browser: http://localhost:${PORT}`); | |
| console.log(`=========================================`); | |
| }); | |