Saturday 28 November 2015

Help! I think I'm having problems with variable scope.

I wrote a "route manager" file for my application. It takes in a routes.json file, and registers the routes in Express, based on whether they use a view or a custom JavaScript file in routes/. Furthermore, if it uses a Jade view, it adds in some variables: if the JSON contains "variables": { "foo": ":bar" }, it adds the variable foo with value req.params["bar"].My problem is that this only works once. For instance, suppose that the Jade view is p=foo, and that the route is /:foo/details:The first time I request /2/details, the page shows "2".From the second time on, whenever I request eg. /5/details it still shows "2".In fact, using debug statements, it turns out that the first time my route generator has options == {"foo": ":bar"}, but the subsequent times it has options == {"foo": "2"}.Any idea of how to fix this? Or perhaps libraries that already accomplish what I'm trying to do?Here is a minimal example of the algorithm in question.

Submitted November 28, 2015 at 10:20AM by ZugNachPankow

No comments:

Post a Comment