To a large extent, solely for educational purposes, I serve both my data and the data from my node server. Right now, I am at the point where I received my client request successfully, created some data based on the specified request, I can register it in a console, etc. Everything is fine up to this point. My problem is that if my data is only an html file that is read in the fs library, it will not appear on the page when I try to execute it in my res.end () or res.write () file . I can see this exactly what I want and expect it to console me, but it just doesn’t appear in the browser. Any help would be greatly appreciated. I set it up to where I process my requests in "if / else", where I have only two "/" scripts(home), in which case I am serving the html file and something else, because the server really only needs to handle these two events. Thanks in advance.
Change This is what I still have:
function responseHandler(req, res) {
res.writeHead(200, {"Content-Type": "text/html"});
if (req.url.match("fav")) {
res.end("");
return;
}
else if (req.url.match("/endpoint")) {
var input = req.url.match(/endpoint\/(.*)/)[1];
var output = endpoint.toHTML(decodeURI(input));
res.end(data);
console.log(input, req.url)
}
else {
fs.readFile("index.html", "utf8", function(err, data) {
console.log("data:" + data);
var input = req.url.match(/endpoint\/(.*)/)[1];
var output = endpoint.toHTML(decodeURI(input));
});
}
res.end();
}
I can see the data in the console, which in the latter case is only my HTML file. It simply will not appear on the page.
source
share