Comments (6)
Are you looking for the ResourceJS path, or the literal url used?
ResourceJS: /resource/:resourceId
Literal: /resource/123456789
from resourcejs.
I am after the literal
Literal: /resource/123456789
from resourcejs.
Hmm, since ResourceJS build for express, its possibly you could still access the url by: req.originalUrl
(express dependent) or req.url
(node http dependent)..
I think originalUrl is what you're looking for, but I haven't actually tested it. Let me know if that works for you.
from resourcejs.
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 ../callback/12345
and this is what I get when I log the req.originalUrl
and req.url
. The fact that I am calling resourcejs via the line resj['/api'].get.call this, req, res, ->
does not affect the current express route.
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 res
that is passed into the after
function. I will take a look at doing this but if you have any suggestions ...
Thanks
from resourcejs.
Ah I understand more now, however, the req.originalUrl should be correct any point inside the manual resourcejs call: console.log 'res.resource', res.resource
from resourcejs.
Unfortunately it would be too late to call out to the mock url by the time we got to console.log 'res.resource', res.resource
. Also I want to apply a general process via a global after
function that will mock out all the calls to any resource. Therefore I need to circumvent all the resourcejs processing and instead call my mock url via the after
function so I can return the mock data rather than the actual resource. To call the mock URL I need the actual URL resource.js was about to use.
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 res
and short circuit the rest of the process and proceed directly to the defined after
function. I can't see how to do this mind you, so if you think this idea is worth a go then I would really appreciate some pointers.
Thanks for taking the trouble.
from resourcejs.
Related Issues (20)
- can't get example in README.md to work HOT 2
- Is there an admin / documentation html-interface for resourcejs? HOT 1
- Return code 200 and empty array instead of error 500 on GET request for empty collection HOT 1
- Type definitions HOT 1
- Allow passing of options down to `save()` method HOT 1
- Add ability to pass options to Document.save()
- Why does `Resource.respond()` call `next()` at the end HOT 2
- Add documentation for `hooks`
- Should `before` and `before[method]` handlers be merged?
- Allow Population on `get()` request
- Allow complex population
- Document all the fields that can be set on `req` in before handlers
- `get()` passes `search` to before hook
- Can't see the swagger UI
- Unable to use get for all data inside my react state HOT 1
- Bug / Question: Virtual Resources
- The regex doesn't work as well
- Fast JSON patch needs to be updated. HOT 2
- How to add custom Error Handler?
- Support mongoose 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from resourcejs.