-
Notifications
You must be signed in to change notification settings - Fork 485
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
change http server callback function identity to match the normal api #171
base: master
Are you sure you want to change the base?
Conversation
I think the args coming in are supposed to be the chunks that got matched by any patterns in the route. I think. |
the matches still get passed into the callback with this patch |
That'll break the api for all of us using director and expecting the arguments to be in a particular place. Unless you change it to |
a new option would be the way to go, i'll look into it when i get some more time or would welcome someone more familiar with the director repo to give it a shot |
Also it would be nice if there was a test in director that enforced this API Sent from my iPhone On Dec 20, 2012, at 12:37 AM, Rod Vagg [email protected] wrote:
|
I agree with having an option |
@maxogden I've been wanting to make this change for a while. Eventually This is, however, massively breaking to all existing director code and needs to be rolled out slowly to users on the way to
While the meaning of |
@indexzero well you would never have request and response objects in the browser or cli, only http, so it doesnt make sense for the 2 non http use cases. the requirement of needing I personally dont use director in cli or browser and would rather have the http behavior act like node core, so maybe an initialization option to change the signature is the best way forward here. something like:
I'll try to implement this and add it to this pull req |
:( |
@maxogden One of the core goals of director is to create a common abstraction across these three routing scenarios since they are all actively used @nodejitsu and to reuse routes across them. If we have a core and expected inconsistency between them we will be farther from our goal. Although there is no When this came up previously in conversation the thoughts were something like: browser function (input, output) {
console.log(req) // { url: document.window.location.host, path: ['foo', 'bar'] }
} CLI function (cmd, log) {
console.log(cmd) // { path: ['foo', 'bar'] }
} Going back to my roots here I used to maintain journey with @cloudhead. The thing that made journey preferable to me over express in the early days was the mapping between regular expressions and function scoping. e.g. router.path(/apps\/([\w\-]+)/, function () {
router.path(/([\w\-]+)\/snapshots/, function () {
//
// List snapshots
//
this.get(function (username, appname) {
//..
});
//
// List snapshots
//
this.put(/([\w\-]+)/, { stream: true }, function (username, appname, id) {
//
// Pipe the snapshot (this.req) somewhere
//
});
});
}); Since there is no explicit naming provided to these regular expressions in the routing table they end up having to be stored as an Array (as is done in express in e.g. In the above example //
// I prefer descriptive variable names
//
assert.equal(username, req.params[0]);
assert.equal(appname, req.params[1]);
assert.equal(snapshotId, req.params[2]); Given the importance of matching core node http method signature the compromise here I see here is to stop allowing regular expressions as parameters to If users wish to use a regular expression they must do so via e.g. router.param('username', /([\w\-]+)/);
router.param('appname', /([\w\-]+)/);
router.param('snapshotId', /([\w\-]+)/);
router.path('/apps/:username', function () {
router.path(':appname/snapshots', function () {
//
// List snapshots
//
this.get(function (req, res) { // or maybe req, res, params
// req.username
// req.appname
});
//
// List snapshots
//
this.put('/:snapshotId', { stream: true }, function (req, res) {
//
// Pipe the snapshot (this.req) somewhere
//
// req.username
// req.appname
// req.id
});
});
}); |
@maxogden @pksunkara I think in my discussion of the larger issue I neglected to make clear that this is fine if we make it a configurable option turned off by default. It's a step on the road to |
Oh yeah and thanks @maxogden 👍 |
I wanted to do this (so that I could use the many functions on NPM that accept the
(req, res)
identity):instead of this
there might be a better way to implement this but given the level of abstraction inside the director codebase I couldn't figure out anything more elegant. I also made sure all the tests still pass