i18next/i18next-http-middleware

Unable to control Cache-Control

Creatium opened this issue · 6 comments

Hey, it's me again, with another issue on another plugin.

I set to use /locales/:lng/:ns endpoint with middleware like this:

app.get("/locales/:lng/:ns", middleware.getResourcesHandler(i18next, {
   maxAge: 0,
   cache: false,
}));

This endpoint now responds with Cache-Control headers set to public, max-age=2592000. No matter what cache settings I provide (true, false, maxAge 0 or none at all) it stays the way it is. And same goes with other endpoints provided in your documentation.

Using NGINX, I have add_header Cache-Control "no-cache"; set, no other endpoint in my api has similar headers. So there is something that this middleware does that sets the headers.

The documentation is very limited and I have not found any similar issues.

adrai commented

I just tested it with this line... just setting cache to false: https://github.com/i18next/i18next-http-middleware/blob/master/example/basic/index.js#L74
and it works as expected

Strange. I am unable to find the reason. Using the very same i18next config as in your provided example (except for using the LanguageDetector). Locale endpoints are returning all translations, but in my custom testing endpoint I am able to print keys that are newly added...

Adding ?v=1 to the end of endpoint rewrites Cache-Control and the updated translation appears..

Even app.set("etag", false); does not work for these endpoints.

adrai commented

can you reproduce your issue with https://github.com/i18next/i18next-http-middleware/blob/master/example/basic/index.js#L74 example locally? NODE_ENV=production node index.js

I can't. Even my own code build runs fine locally. Only in my production server I get uncontrolled Cache-Control headers.

adrai commented

Then there's nothing I can do, sorry.

Yep, found the reason. NGINX took initially set Cache-Control from endpoint and cached the results for the period it was set (ignoring the nginx config period). Clearing the cache solved the issue.