为什么在启用了 TypeScript 和 Cors 的 NestJS 中使用 PATCH 方法时出现 CORS 错误?

问题描述 投票:0回答:1

NestJs 中 PATCH 方法被 cors 阻塞

问题如下:预检响应中的 Access-Control-Allow-Methods 不允许方法 PATCH。

这就是我将 cors 连接到我的应用程序的方式。

  app.enableCors({
    origin: true,
    methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'],
    credentials: true,
  });
typescript cors nestjs
1个回答
0
投票

就我而言,问题出在“允许 CORS:Access-Control-Allow-Origin”chrome 扩展。

我的 cors 配置是:

app.enableCors({
    origin: (origin, callback) => callback(null, true),
    methods: 'GET,POST,PUT,DELETE,PATCH,OPTIONS',
    allowedHeaders: '*',
    credentials: true,
    preflightContinue: true,
});

但是,我在使用 PATCH 方法时仍然遇到了 CORS 错误。 要解决这个问题,我必须转到扩展程序的设置并启用“允许 PATCH 方法”

enter image description here

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.