moved folder structure

This commit is contained in:
hugo gogo
2022-10-14 18:48:38 +02:00
parent 87a7e75de1
commit b35cf724bc
429 changed files with 57 additions and 41 deletions

View File

@@ -0,0 +1,9 @@
<!Doctype html>
<html>
<head>
<title>title</title>
</head>
<body>
<h1>hello world</h1>
</body>
</html>

View File

@@ -0,0 +1,38 @@
const http = require('http')
const fs = require('fs')
const url = require('url')
const sendMyFile = (file, res) => {
fs.readFile(file, (err, data) => {
if (!err) {
res.writeHead(200, {
'content-type': 'text/html; charset=utf-8'
})
res.end(data)
}
else
res.writeHead(404).end('file not found')
})
}
const server = http.createServer((req, res) => {
let pathName = url.parse(req.url).pathname
if (req.method === "GET") {
if (pathName === "/")
sendMyFile("index.html", res)
else if (pathName === "/index.html")
sendMyFile("index.html", res)
else
res.writeHead(404).end('wrong url')
}
})
server.get('/', (req, res) => {
res.sendFile(__dirname + "/" + "index.html")
})
const port = 3000
server.listen(port, console.log(`listening on port ${port} with express`));

View File

@@ -0,0 +1,39 @@
//const https = require('node:https')
const http = require('http')
const fs = require('fs')
const url = require('url')
const rootName = (name) => {
fullName = __dirname + name
return fullName
}
const sendHtml = (pathName, response) => {
console.log(` name: ${pathName}`)
console.log(`namePath: ${rootName(pathName)}`)
fs.readFile(rootName(pathName), (err, data) => {
if (err) {
response.writeHead(404)
response.end('file not found')
}
else {
response.writeHead(200, {
'content-type': 'text/html; charset=utf-8'
})
response.end(data)
}
})
}
const server = http.createServer((request, response) => {
let pathName = url.parse(request.url).pathname
// read file
if (pathName.endsWith(".html"))
sendHtml(pathName, response)
})
server.listen('8080')