Giter VIP home page Giter VIP logo

Comments (6)

zackurben avatar zackurben commented on July 26, 2024

Are you looking for the ResourceJS path, or the literal url used?

ResourceJS: /resource/:resourceId
Literal: /resource/123456789

from resourcejs.

biofractal avatar biofractal commented on July 26, 2024

I am after the literal

Literal: /resource/123456789

from resourcejs.

zackurben avatar zackurben commented on July 26, 2024

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.

biofractal avatar biofractal commented on July 26, 2024

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.

zackurben avatar zackurben commented on July 26, 2024

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.

biofractal avatar biofractal commented on July 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.