I'm trying to write a function that returns the main page, index.html. However, when I remove the line
requestpath += options.index
I get the following error:
500: encountered error while processing GET of "/"
Without that line, wouldn't the request be localhost:3000/, which should serve index.html?
I'm guessing it has something to do with the fs.exist function at the end, but I'm not sure.
var return_index = function (request, response, requestpath) {
var exists_callback = function (file_exists) {
if (file_exists) {
return serve_file(request, response, requestpath);
} else {
return respond(request, response, 404);
}
}
if (requestpath.substr(-1) !== '/') {
requestpath += "/";
}
requestpath += options.index;
return fs.exists(requestpath, exists_callback);
}
options is equal to
{
host: "localhost",
port: 8080,
index: "index.html",
docroot: "."
}
requestpathdo? It looks like the difference would be absolute and relative pathsoptions.index? Can youconsole.log(options.index);and tell us what it returns?