NestJs 中 PATCH 方法被 cors 阻塞
问题如下:预检响应中的 Access-Control-Allow-Methods 不允许方法 PATCH。
这就是我将 cors 连接到我的应用程序的方式。
app.enableCors({
origin: true,
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'],
credentials: true,
});
就我而言,问题出在“允许 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 方法”