nuxt-community / axios-module

Secure and easy axios integration for Nuxt 2
https://axios.nuxtjs.org
MIT License
1.19k stars 247 forks source link

Nuxt caching #472

Open SajjadHadi opened 3 years ago

SajjadHadi commented 3 years ago

Hello, I've just deployed a nuxt app to the server, but it caches in a bad way. in any device, logged in or not, I get one user information, it's cookie and token! I tried to find out what is the problem, I searched and now I think because cache-control: public with max-age=31536000, now I've tried to set it to private or no-cache.

I have two questions:

  1. which cache-control value should I use? private or no-cache, etc? or even is this problem is because of caching?

  2. when I try to set headers of axios in nuxt.config.js , I get this error:

Access to XMLHttpRequest at 'url of the backend' from origin 'http://localhost:3000' has been blocked by CORS policy: Request header field cache-control is not allowed by Access-Control-Allow-Headers in preflight response.

I've tried to set Access-Control-Allow-Headers but it did'n work and gives me same error like above, my nuxt.config.js, the axios part is like this:

axios: {
        baseURL: 'backend',
        headers: {
            common: {
                'Access-Control-Allow-Headers': 'cache-control',
                'cache-control': 'private',
            },
        },
    }

thank you.

farnabaz commented 3 years ago

Access-Control-Allow-Origin is a response header you need to add this header to the response from your server. More likely you should add cache-control as a response header.

Also checkout Preventing caching on MDN