Coder Social home page Coder Social logo

Comments (9)

mindmelting avatar mindmelting commented on August 20, 2024

+1

from express-unless.

goncaloneves avatar goncaloneves commented on August 20, 2024

+1

from express-unless.

mikelax avatar mikelax commented on August 20, 2024

+1, just ran into this today. For the time being I will write a custom function to achieve the desired logic, but it seems like a simple addition of another attribute.

from express-unless.

razvanilin avatar razvanilin commented on August 20, 2024

+1

from express-unless.

emaddoma avatar emaddoma commented on August 20, 2024

+1

from express-unless.

goncaloneves avatar goncaloneves commented on August 20, 2024

The way I accomplished this with a custom unless function:

app.use(middleware().unless(function(req) {
  return (
      req.originalUrl === '/endpoint1' && req.method === 'GET' ||
      req.originalUrl === '/endpoint2' && req.method === 'POST'
  );
}));

Hope it helps.

from express-unless.

chuckconway avatar chuckconway commented on August 20, 2024

@goncaloneves Thanks for the code. It works, but it would be nice if it was baked in.

from express-unless.

zhiyelee avatar zhiyelee commented on August 20, 2024

@chuckconway @goncaloneves feature added in v0.3

from express-unless.

molaeiali avatar molaeiali commented on August 20, 2024

I'm using unless with express-jwt to whitelist some endpoints from having to have token, but looks like it does not respect the http method I provide

app.use(
    jwt({
      secret: process.env.JWT_SECRET
    }).unless({
       path: [
            //...
           { url: 'estimate/category', method: 'GET' },
            //...
       ]
    })

as I understand, it should whitelist 'estimate/category' just for GET method, in other words, I have to provide token if it is POST or PATCH and don't have to provide token if it's GET

but it is whitelisting it for all methods.

I think the problem is here:

skip = skip || methods.indexOf(req.method) > -1;

Shouldn't it be a && here?
This code says here if skip exists, methods are not important

Environment

I'm using:
"express": "4.17.1",
"express-jwt": "5.3.3",
"express-unless":"0.3.1"

from express-unless.

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.