Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support calling route functions in custom context #11

Open
miracle2k opened this issue Apr 1, 2011 · 0 comments
Open

Support calling route functions in custom context #11

miracle2k opened this issue Apr 1, 2011 · 0 comments

Comments

@miracle2k
Copy link

It seems it's currently not impossible to place the functions handling the routes outside of the closure, if they need access to the parent context, say things like a database connection.

var FooService = function() {
   this.db = connect();
   router = new(journey.Router);
   router.root(this.handleRequest);
}

FooService.prototype.handleRequest = function(req, res) {
    // How do I access the database connection?
}

The documentation points out that I can access the request object via "this.request" in the handle function, but I'm not sure why that is important when the same object is also passed as an argument.

I've seen one other node library that accepted a globalContext argument, which it would then use with apply() when calling functions. which struck me as a nice idea (I'm a node.js/Javascript noob though).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant