apicache icon indicating copy to clipboard operation
apicache copied to clipboard

Cross-Origin Request Blocked

Open rochapablo opened this issue 5 years ago • 3 comments

When using apicache and the page it's cached, I start to get the follow error and can't access my page anymore. This only when I publish to Heroku (production), local it's working.

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://mywebsite.... (Reason: missing token ‘authorization’ in CORS header ‘Access-Control-Allow-Headers’ from CORS preflight channel).
apicache.options({
  debug: false,
  redisClient: redis.createClient({ url: 'redis://...' }),
});
const cache = apicache.middleware;
app.use(cache('25 minutes')); 
cors: {
    origin: ['https://mywebsite....'],
},

What could I be doing wrong?

"apicache": "^1.5.2",
"cors": "^2.8.5",
"routing-controllers": "^0.8.0",
"redis": "^2.8.0",

https://github.com/kwhitley/apicache/issues/92

rochapablo avatar Dec 15 '19 14:12 rochapablo

Same issue here when caching with apicache and CORS: only the first request (which misses the cache) has the right answer headers. As soon as the request hits the cache, there are no CORS headers and the browser (or client application) refuses to read the content.

soukron avatar Jan 29 '21 12:01 soukron

Same Issue here

EinfachHans avatar Mar 22 '21 16:03 EinfachHans

Adding access-control-allow-origin (in lowercase) to headerBlacklist in the global options seems to solve the problem.

gabmontes avatar May 25 '21 02:05 gabmontes