// načtení knihoven const http = require("http"); const fs = require("fs"); const path = require("path"); //vytvoření chování serveru const server = http.createServer((req,res) => { //přečti url const filePath = req.url === "/" ? "pages/index.html" : `pages${req.url}.html`; //načti hledaný soubor fs.readFile(path.join(__dirname,filePath),"utf8", (err,data) => { if (req.url == "/youtube") { res.writeHead(302, {"Location":"https://www.youtube.com"}); res.end(); } if (err) { //když se nenalezne soubor res.writeHead(404, {"Content-Type" : "text/html"}); res.end("

404 { if (err) { //když se nenalezne ani menu res.writeHead(500, {"Content-Type" : "text/html"}); res.end("

500 - Internal Server Error `,``) res.writeHead(200, {"Content-Type" : "text/html"}); res.end(data); } }) } }) }) const PORT = 3000; //spuštění serveru server.listen(PORT, () => { console.log(`Server běží na http://localhost:${PORT}`); })