-
-
Notifications
You must be signed in to change notification settings - Fork 764
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
Ability to provide config for i18next-express-middleware #68
Comments
Very strange, I remember writing this regex to fix that exact issue. Moreover, I cannot seem to reproduce this bug in the example: Can you please provide a demo repo that reproduce this bug? I'm sure we can get this fixed very quickly. Thanks for your patience. |
Thank you for your answer. Here's the minimal setup that I'm using: https://github.com/thebat93/next-i18next-example I think the problem is that I'm not actually using localePaths. For my project I need to have a locale subpath for the default language too with redirections from paths without locale subpaths in them. When I set localePaths to true the regex that you mentioned is applied and the cookie is set correctly, but I don't get the feature that I want. I saw the open PR with just the feature that I want. Maybe it will be a solution for me. |
@thebat93 Thanks - quick fix with 54f26f2. In the future we might want to use a I think to do this we'd need the full list of page routes. As per this comment, I think we'd have to do something like: const pages = await glob('pages/**/*.js', { cwd: __dirname }) Which is not an approach I care to get into at the moment. If more people run into this issue we can readdress it. |
Thanks for the quick fix. Unfortunately it resolved the problem only with routes that have '/_next' and '/static' in them, but I also have routes that start with '/fonts' and '/v0'. These routes still mess up the cookie. |
Did you read my comment...? I addressed that exact problem. |
I did, but I don't see how it applies to the problem that I need to solve now. The cookie is still set incorrectly. If I use i18next-express-middleware and add ignoreRoutes for '/_next', '/static' and '/fonts' everything works as intended. I just wish there was a way to configure the middleware in your library. Right now I can't fully apply it to my case and have to use the middleware for Express. |
@thebat93 I am very curious where you added ignoreRoutes? I'd like to ensure that '/_next', '/static' and '/fonts' are not being processed for my app as well! |
@anthonywebb There's currently no way to do this in I can add an options object to the |
It's not possible to provide the config object with ignoreRoutes to the middleware using this library. So, something like this: const app = next({ dev: process.env.NODE_ENV !== 'production' })
const handle = app.getRequestHandler();
(async () => {
await app.prepare()
const server = express()
// Ignored routes
server.use(express.static(__dirname + '/public'));
server.use('/locales', express.static(__dirname + '/locales'));
server.use('/v0/', someApiMiddleware);
server.use('/fonts', express.static('./node_modules/fonts/.../'));
// Middleware
nextI18NextMiddleware(nextI18next, app, server)
server.get('*', (req, res) => handle(req, res))
await server.listen(3000)
console.log('> Ready on http://localhost:3000')
})() |
I'll be releasing a fix momentarily. |
Thanks @thebat93 @isaachinman this will be great. The interim fix of just including the middleware after the routes that you want to ignore is fine for me so no rush. |
Released in v0.15.0. |
Hi! Thanks for the great library!
I'm experiencing the following problem:
The first request that I send to the Express server sets the language cookie correctly.
But other requests to internal URLs that include "_next" in their route set the incorrect cookie afterwards.
So, as a result the cookie of the page is the incorrect one.
I think I'm experiencing this because each of my requests is processed by the i18next-express-middleware. I noticed that there is a way to specify routes for the middleware that you want to ignore in the config (https://github.com/i18next/i18next-express-middleware#wire-up-i18next-to-request-object) but I didn't find the same functionality here.
Could I suggest adding this feature to the library or maybe there is another way of resolving my issue?
The text was updated successfully, but these errors were encountered: