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.
27 lines
838 B
27 lines
838 B
//import moduly
|
|
const http = require("http")
|
|
const fs = require("fs")
|
|
const path = require("path")
|
|
|
|
const server = http.createServer((req,res)=>{
|
|
console.log("REQ:",req.url)
|
|
const filePath = req.url === "/" ? "index.html":req.url.slice(1) //nalzeneme soubor
|
|
const fullPath = path.join(__dirname,filePath) //načteme CELOU cestu
|
|
console.log("otevírám:", fullPath)
|
|
|
|
fs.readFile(fullPath,(err,content)=>{
|
|
if(err){
|
|
res.writeHead(404,{"content-type":"text/html; charset=utf-8"})
|
|
res.end("<h1>ERROR</h1><h2>Soubor není </h2>")
|
|
} else {
|
|
res.writeHead(200,{"content-type":"text/html"})
|
|
res.end(content)
|
|
}
|
|
})
|
|
})
|
|
|
|
const PORT = process.argv[2];
|
|
//const PORT = 3000;
|
|
server.listen(PORT,()=>{
|
|
console.log(`Server bezi http://localhost:${PORT}`)
|
|
})
|