samedi 31 janvier 2015

Javascript: why this line is required for functionality?

This function is to return to the main page. But I have one question: When I delete the line requestpath += options.index; why does it give me an error 'encountered error while processing GET of “/“' with response code 500? without that line wouldn't it be localhost:3000/ which would return me to index. I'm guessing it is something with fs.exist function at the end.



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);
}


Any help is appreciated


Edit: option is:



var options = {
host: 'localhost',
port: 8080,
index: 'index.html',
docroot: '.'
};


so option.index will give 'index.html'





Aucun commentaire:

Enregistrer un commentaire