cors icon indicating copy to clipboard operation
cors copied to clipboard

Header not set on error response

Open cyclecycle opened this issue 6 years ago • 2 comments

Hi,

I have a situation where when I receive a response with an error status (in this case status 416), there are no CORS headers present on the response. It works fine with otherwise. Any idea why this could be?

Cheers,

Nick

cyclecycle avatar Jun 13 '19 00:06 cyclecycle

try opts.keepHeadersOnError = true, it will set headers to err.header if an error is thrown.

dead-horse avatar Jun 13 '19 04:06 dead-horse

Hi, thanks for the response. I had tried this, doesn't seem to make any difference. err.header is undefined.

I'm instantiating like this (using with sqlite-to-rest):

const corsOptions = {
  origin: '*',
  allowHeaders: 'range',
  keepHeadersOnError: true,
}

getSqliteRouter({ dbPath })
  .then(router => {
    app.use(router.routes())
      .use(router.allowedMethods())
      .use(cors(corsOptions))
      .listen(PORT);
  });

cyclecycle avatar Jun 13 '19 11:06 cyclecycle