From a49723477c8c2d6182de8c9269569782d7b8d64e Mon Sep 17 00:00:00 2001 From: Sayazhan Date: Sat, 22 Aug 2026 11:46:39 +0000 Subject: [PATCH] add server.js for static serving --- server.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 server.js diff --git a/server.js b/server.js new file mode 100644 index 0000000..4d2a7cf --- /dev/null +++ b/server.js @@ -0,0 +1,27 @@ +const http = require("http"); +const fs = require("fs"); +const path = require("path"); + +const PORT = process.env.PORT || 3000; + +const mimeTypes = { + ".html": "text/html; charset=utf-8", + ".css": "text/css; charset=utf-8", + ".js": "application/javascript; charset=utf-8", + ".json": "application/json; charset=utf-8" +}; + +http.createServer((req, res) => { + let file = req.url === "/" ? "/index.html" : req.url.split("?")[0]; + const full = path.join(__dirname, file); + + if (full.startsWith(__dirname) && fs.existsSync(full) && fs.statSync(full).isFile()) { + const ext = path.extname(full); + const type = mimeTypes[ext] || "application/octet-stream"; + res.writeHead(200, { "Content-Type": type }); + return res.end(fs.readFileSync(full)); + } + + res.writeHead(404); + res.end("Not found"); +}).listen(PORT, () => console.log("VOLS Registry на порту " + PORT));