loopback-next icon indicating copy to clipboard operation
loopback-next copied to clipboard

404 OPTION - Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

Open foxMclion opened this issue 6 years ago • 5 comments

Loopback is always sending 404 responses to preflight requests (I'm sending application-json content type requests). It seems loopback is not sending the cors response header.

404 OPTION - Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

Steps to reproduce

Use this configuration for the loopback 4 application:

export async function main(options: ApplicationConfig = {}) {
  const app = new BackendApplication({
    shutdown: {
      signals: ['SIGTERM', 'SIGINT', 'SIGUSR2'],
      gracePeriod: 5000,
    },
    rest: {
      port: 3011,
      expressSettings: {
          'x-powered-by': false,
      },
      cors: {
        origin: '*',
        methods: 'GET,POST,PATCH,DELETE,PUT,OPTIONS',
        preflightContinue: true,
        optionsSuccessStatus: 204,
        maxAge: 86400,
        credentials: true
      },
    },
  });

foxMclion avatar May 16 '20 16:05 foxMclion

@foxMclion You need to update your sequence.ts (or use DefaultSequence) if it was generated by an older cli. Please refer to https://github.com/strongloop/loopback-next/issues/5368#issuecomment-626233755

tipuban avatar May 16 '20 17:05 tipuban

@tipuban Thanks for the pointer. I'm closing this one as duplicate of #5368.

raymondfeng avatar May 16 '20 17:05 raymondfeng

Thanks, I modified the sequence but now I'm getting a 422 unprocessable entity for my POST. Now the OPTIONS return 200 as per the config. I'm not sure if the 422 is CORS related.

foxMclion avatar May 16 '20 17:05 foxMclion

solved thanks, the 422 is the openapi validation.

foxMclion avatar May 16 '20 17:05 foxMclion

i used the same cors settings but it's not working in loopback 3

IamJosephdaramola avatar Aug 20 '20 08:08 IamJosephdaramola