cloudhead / cloudhead/journey

Support calling route functions in custom context

Open
#11 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
322
Forks
26
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.