-
Notifications
You must be signed in to change notification settings - Fork 31
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
Within an after function, how can I discover the actual route used? #22
Comments
after
functionafter
function, how can I discover the actual route used?
after
function, how can I discover the actual route used?
Are you looking for the ResourceJS path, or the literal url used? ResourceJS: |
I am after the literal Literal: /resource/123456789 |
Hmm, since ResourceJS build for express, its possibly you could still access the url by: I think originalUrl is what you're looking for, but I haven't actually tested it. Let me know if that works for you. |
Unfortunately using the express urls doesn't work. This is because I am not actually calling into resource.js using express instead I am using your cool internal method calls. Here is a partial code snippet to show this: router.get '/callback/:key', (req, res, next) ->
req.noResponse = true
resj = req.app.resourcejs
async.waterfall [
(cb)->
req.query = key : req.params.key
resj['/api'].get.call this, req, res, ->
console.log 'res.resource', res.resource
return cb res.resource.status unless res.resource.status is 200
cb null, res.resource.item[0] So the actual express call here is I think I need to find a place in the resourcejs code where the actual url is know (the final url that contains the actual ids etc) and store this on the Thanks |
Ah I understand more now, however, the req.originalUrl should be correct any point inside the manual resourcejs call: |
Unfortunately it would be too late to call out to the mock url by the time we got to Perhaps I can somehow insert some code into your middleware feature, where the correct url will be available? I could then set the url onto the Thanks for taking the trouble. |
I am attempting to add the ability to mock out calls to resource.js. When a call is made to a resource.js end-point, the actual call is swapped out for an equivalent call to a mock url (apiary blueprint in my case).
I am doing this in the following way:
The
before
function prevents resource.js from processing the call. Theafter
function composes the mock-url and calls it returning any results. The mock-url consists of two parts, thebaseUrl
(the static part of the url pointing to the mock api) and theresourceUrl
, the actual route that resource.js would have used if it had been allowed to process.The problem I have is getting hold of the
resourceUrl
component. The code above sees me trying theres.resource.route
but this isundefined
. I think this would be wrong in any case as I really need the final route resource.js would be using, including any ids, filters etc.Do you have any idea if this route is available currently? If not, some pointers to the best place to store this route for each call so that it is available to the
after
function would be greatly appreciated.Thanks
The text was updated successfully, but these errors were encountered: