new course on openclassroom
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
|
||||
const http = require('http')
|
||||
const fs = require('fs')
|
||||
const url = require('url')
|
||||
@@ -11,28 +12,52 @@ const sendMyFile = (file, res) => {
|
||||
res.end(data)
|
||||
}
|
||||
else
|
||||
res.writeHead(404).end('file not found')
|
||||
{
|
||||
res.writeHead(404)
|
||||
res.end('file not found')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const server = http.createServer((req, res) => {
|
||||
//const server = http.createServer((req, res) => {
|
||||
//
|
||||
// let pathName = url.parse(req.url).pathname
|
||||
//
|
||||
// if (req.method === "GET") {
|
||||
// if (pathName === "/")
|
||||
// sendMyFile(__dirname + "/index.html", res)
|
||||
// else if (pathName === "/index.html")
|
||||
// sendMyFile(__dirname + "/index.html", res)
|
||||
// else
|
||||
// {
|
||||
// res.writeHead(404)
|
||||
// res.end('wrong url')
|
||||
// }
|
||||
// }
|
||||
//})
|
||||
|
||||
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')
|
||||
}
|
||||
})
|
||||
let myExpress = () => {
|
||||
return http.createServer((req, res) => {
|
||||
let pathName = url.parse(req.url).pathname
|
||||
if (req.method === "GET") {
|
||||
if (pathName === "/")
|
||||
sendMyFile(__dirname + "/index.html", res)
|
||||
else
|
||||
{
|
||||
res.writeHead(404)
|
||||
res.end('wrong url')
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
server.get('/', (req, res) => {
|
||||
res.sendFile(__dirname + "/" + "index.html")
|
||||
})
|
||||
//server.get('/', (req, res) => {
|
||||
// res.sendFile(__dirname + "/" + "index.html")
|
||||
//});
|
||||
|
||||
const port = 3000
|
||||
server.listen(port, console.log(`listening on port ${port} with express`));
|
||||
const server = myExpress();
|
||||
|
||||
const port = 3001;
|
||||
server.listen(port, console.log(`listening on port ${port}`));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user