I have a few documentation pages I want to serve. Instead of writing something like the following, I want to essentially server them all without writing this code for every page:
jade.renderFile("/documentation/gettingStarted", {}, function(err, str) {
if(err) throw err;
response.send(str);
});
I also would like a simple "Next Page" at the bottom of these pages, with order defined in the following array:
var pages = ["installation", "gettingStarted"];
The part I'm stuck on is that iterating through each page in my array with app.get
:
for(var i = 0; i < pages.length; i++) {
var pagePath = "documentation/" + pages[i];
app.get("/" + pagePath, function(request, response) {
jade.renderFile(pagePath + ".jade", {}, function(err, str) {
if(err) throw err;
response.send(str);
});
});
}
With the block above I would hope that it would server pages on the following requests:
/documentation/installation
/documentation/gettingStarted
It works for one page, but due to the fact jade.renderFile(...)
is called on GET, it will simply use the variables left over from the initialisation, meaning both pages will only return the last page (gettingStarted) because pagePath
will be kept the same for both requests.
Is there anyway to serve a bunch of files dynamically? Is it required to make call app.get
for every individual page?