Skip to content
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

Add the ability to skip the mdleware on ajax requests on a specific route #57

Closed
agalazis opened this issue Apr 8, 2016 · 7 comments
Closed

Comments

@agalazis
Copy link
Contributor

agalazis commented Apr 8, 2016

I know that you appreciate pull requests and I was tempted to just implement this and do pull request but then I thought it would be better to discuss it in order to make sure I don't violate the philosophy of the middle-ware
One way is introducing igroreAjaxRoutes in the middle-ware configuration.
Another way would be to provide an ignoreRoute function:

 ignoreRoute:function(req,ignoreRoutes){
                       if (//do whatever checks you want){
                              return true;//to ignore
                      }
                      return false;//to use the route
}

then use that function to check whether to skip and call next()

I guess the first is more clear but the second covers more cases.

@jamuhl
Copy link
Member

jamuhl commented Apr 8, 2016

like the idea ignoreRoute function. if array do what we do right now...if function call it with req and do next if true is returned.

PR is very welcome....;)

@isaachinman
Copy link

@jamuhl It's an old one, but is this on a roadmap?

@jamuhl
Copy link
Member

jamuhl commented Nov 6, 2018

@isaachinman there is no "roadmap" for the express middleware...PRs get merged on demand. If this is needed for the next.js implementation i can look into this the next days (it's a small thing to add).

@isaachinman
Copy link

isaachinman commented Nov 6, 2018

@jamuhl I'm trying to match routes like this:

/:lng/my-route

However, even with a whitelist in place, the express middleware is catching routes like:

/static/locales/de/common.json

And it's actually setting the i18next cookie value to static. Not sure if this is an error on my part, or expected behaviour. Any tips?

@isaachinman
Copy link

Not sure if this would be better solved by something like ignoreRoute, or just the ability to provide a custom substring to perform before doing lookups.

@jamuhl
Copy link
Member

jamuhl commented Nov 7, 2018

hm...cookie should be set like: https://github.com/i18next/i18next-express-middleware/blob/master/src/languageLookups/cookie.js#L31

regarding the middleware getting triggered for statics - might be that handling changed from the road express 2 -> 4 --- so i will add that ignoreRoute function asap to handle such cases

@jamuhl
Copy link
Member

jamuhl commented Nov 7, 2018

published in [email protected]

ignoreRoutes: function(req, res, options, i18next) { /* return true to ignore */ }

@jamuhl jamuhl closed this as completed Nov 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants