小编Jua*_*pez的帖子

在 Firebase Functions 服务器中设置 Swagger Ui

我在 Firebase Cloud Functions 上开发了一个 API,我想包含它的文档路径。我正在使用 swagger,我可以在本地成功测试它 (localhost:PORT/docs),但是当我将该函数部署到 Firebase 时它不起作用,它会将我重定向到授权页面。

我想我明白了这是为什么:

假设我的云函数的名称是 cfunc。那么它的基本 URL 类似于https://region-name-project-name.cloudfunctions.net/cfunc。基于我如何包含 swagger 文档:

const swaggerDoc = require('./docs/swagger.config.json')
app.use(
    '/docs',
    allowCors,
    swaggerUi.serve,
    swaggerUi.setup(swaggerDoc, {
        customCssUrl: '/assets/swagger.css',
        customSiteTitle: 'My Function Title',
        customfavIcon: '/assets/logo.ico',
        swaggerOptions: {
            supportedSubmitMethods: [] //to disable the "Try it out" button
        }
    })
)
Run Code Online (Sandbox Code Playgroud)

文档应位于https://region-name-project-name.cloudfunctions.net/cfunc/docs。当我尝试访问该 URL 时,在浏览器 DevTools 中观看“网络”,它尝试在该 URL 上执行 GET 响应 304,然后重定向到https://region-name-project-name.cloudfunctions.net/docs,这就是是什么调出了 Google 身份验证页面,因为没有名为“docs”的云函数,所以 Google 认为我正在尝试访问 Firebase 云函数中的其他内容(如果我执行类似https://region-name- 的操作,也会发生同样的情况)项目名称.cloudfunctions.net/tomato

但我仍然不知道如何修复此重定向或为什么会发生这种情况。我尝试将 Cloud Function URL 添加到 swagger.config.json …

node.js firebase swagger-ui google-cloud-functions

2
推荐指数
1
解决办法
1006
查看次数