Я пытаюсь изучить nodeJS и пытаюсь создать сервер и вызвать страницу по умолчанию и страницу контактов, как показано ниже.
var http = require('http');
var path = require('path');
http.createServer(function (request, response) {
var lookup = path.basename(decodeURI(request.url));
/**In the below if condition, if I use loopup === "/", I will get 404 error, but If I use lookup === "", I get the response. I want to know why */
if(lookup === "") {
response.writeHead(200, { "content-type": "text/html" }); // get the html format
response.write("<!DOCTYPE html><html>");
response.write("<head>");
response.write("<title>Ex 02</title>");
response.write("</head>");
response.write("<body>");
response.write("<div> About me!</div>");
response.write("</body></html>");
response.end();
}
if (!response.finished) {
response.writeHead(404, { 'Content-Type': 'text/html' });
response.end('Page Not Found!');
}
// response.writeHead(200, {"content-type": "text/html"});
}).listen(3000);