Skip to content

Support calling route functions in custom context #11

@miracle2k

Description

@miracle2k

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions