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.
25 lines
934 B
25 lines
934 B
const http = require("http");
|
|
const fs =require("fs");
|
|
const path = require("path");
|
|
|
|
const server = http.createServer((req,res) =>{
|
|
const filePath = req.url === "/" ? "index.html" : req.url.slice(1);
|
|
const fullPath = path.join(__dirname,filePath)
|
|
console.log("Open: "+fullPath)
|
|
|
|
fs.readFile(fullPath,(err,content) => {
|
|
if(err){
|
|
res.writeHead(404, {"content-type":"text/html"});
|
|
//vlastní 404 error zpráva
|
|
res.end("<h1> Jejda, je to rozbite <br> aneb <br> 404 </h1><a href=\"/\">HOME</a>") // (\") takzvaný eskejpování pro ignorování uvozovek v textu ohraničený stejnými uvozovkami
|
|
} else {
|
|
res.writeHead(200, {"Content-type":"text/html"});
|
|
res.end(content);
|
|
}
|
|
})
|
|
});
|
|
const PORT = 3000;
|
|
server.listen(PORT, () => {
|
|
console.log(`Server running at http://localhost:${PORT}/ \n Ctrl+C pro vypnuti`)
|
|
});
|
|
//node index.js
|