i18next / i18next-http-middleware

i18next-http-middleware is a middleware to be used with Node.js web frameworks like express or Fastify and also for Deno.
MIT License
150 stars 28 forks source link

Unable to control Cache-Control #68

Closed Creatium closed 6 months ago

Creatium commented 6 months ago

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 6 months ago

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

Creatium commented 6 months ago

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 6 months ago

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

Creatium commented 6 months ago

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

adrai commented 6 months ago

Then there's nothing I can do, sorry.

Creatium commented 6 months ago

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.