【问题标题】:Adding a server to nestjs swagger gives a permission error向nestjs swagger添加服务器会出现权限错误
【发布时间】:2021-09-13 16:09:23
【问题描述】:

当我将新服务器添加到nestjs DocumentBuilder .addServer('http://localhost:7071') 时,当我尝试在生成的招摇页面上执行路由时会出现权限错误。

在浏览器控制台它会抛出这个错误:

Refused to connect to 'http://localhost:7071/api/session/signin' because it violates the following Content Security Policy directive: "default-src 'self'". Note that 'connect-src' was not explicitly set, so 'default-src' is used as a fallback.

Refused to connect to 'http://localhost:7071/api/session/signin' because it violates the document's Content Security Policy.

我已经在 Nestjs 应用中启用了 cors,但运气不好!

app.enableCors();

也许我在 DocumentBuilder 中遗漏了一些安全策略?像.addSecurity() 这样的东西?如果是这种情况如何添加此安全策略?

【问题讨论】:

  • 7071端口上运行的服务器是否允许来自运行swagger页面的服务器的调用?
  • 是的,服务器正在接受来自任何客户端的连接

标签: node.js swagger nestjs openapi nestjs-swagger


【解决方案1】:

此错误是由错误的 CORS 配置引起的。修复它:

  • 通过添加更新招摇:
.addServer('http://localhost:3000')
  • 在 CORS 配置中添加来源(您正在使用的地址):
app.enableCors({origin: 'http://localhost:3000'});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-15
    • 2021-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-20
    • 1970-01-01
    相关资源
    最近更新 更多