You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
751 B
28 lines
751 B
// 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) => {
|
|
const filePath = req.url === "/" ? "index.html" : req.url.slice(1);
|
|
|
|
const fullPath = path.join(__dirname,filePath)
|
|
|
|
fs.readFile(fullPath, (err, content) => {
|
|
if(err) {
|
|
res.writeHead(404, {"Content-Type":"text/html"})
|
|
res.end("<h1>404 not Found</h1>");
|
|
} else {
|
|
res.writeHead(200, {"Content-Type":"text/html"})
|
|
res.end(content);
|
|
}
|
|
})
|
|
})
|
|
|
|
const PORT = 3000;
|
|
|
|
//spuštění serveru
|
|
server.listen(PORT, () => {
|
|
console.log(`Server běží na http://localhost:${PORT}`);
|
|
})
|
|
|