Git Product home page Git Product logo

Comments (5)

mcavage avatar mcavage commented on April 30, 2024

Hi Diego,

So - I'm not really sure what you mean. If you just define some handlers before the routes, this should be possible? I.e.:

server.use(function checkAPIVersion(req, res, next) {
  if (req.path == "/a/nice/path" && !req.headers['x-api-version'])
    req.headers['x-api-version'] = "1.1.0";

  if(req.headers['x-api-version'] == "1.1")
     req.headers['x-api-version'] = "1.1.0";

  return next();
});

server.get({...}, function(req, res, next) { ... });

That does what you're asking for I think?

from node-restify.

dtorres avatar dtorres commented on April 30, 2024

I tried that, it disn't work. then I looked at the code and the process goes like this

Find Route -> Run checkAPIVersion() and other server.use -> run Route

I need to execute it before it finds the route because checkAPIVersion() modifies the request to go for another route.

checkAPIVersion() -> Find Route -> server.use stuff -> run Route

from node-restify.

mcavage avatar mcavage commented on April 30, 2024

Oh ok, now I understand what you meant. Ok - yeah there's nothing there now that will do this, I'll think about how to add a global "pre" handler or chain or something.

from node-restify.

mcavage avatar mcavage commented on April 30, 2024

Hi Diego,

Let me know if this pattern works for you.

Thanks,
~Mark

from node-restify.

dtorres avatar dtorres commented on April 30, 2024

Just, perfect.
Thanks.

from node-restify.

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.