简体   繁体   English

当http firebase-functions在模拟器下运行并部署时,是否有办法标准化request.url中的差异

[英]Is there a way to normalise differences in request.url when http firebase-functions running under emulator and deploy

For firebase tools 6.9.2: 对于Firebase工具6.9.2:

When using firebase emulators:start --only functions, hosting where the functions are invoked via a hosting rewrite rule, the functions are invoked with different request url path prefixes than if the functions were deployed to the cloud. 当使用firebase emulators:start --only functions, hosting通过托管重写规则调用功能的托管时,与将功能部署到云中相比,使用不同的请求url路径前缀来调用功能。 For example given a firebase.json hosting snippet such as: 例如给定的firebase.json托管代码段,例如:

    {
      "target": "myapi",
      "public": "./dist/hosting/myapi",
      "rewrites": [{
          "source": "/api/myapi/*",
          "function": "myapi"
        }
      ]
    },

When deployed to firebase, the myapi function will be called with a request url that starts with: /api/myapi/ 部署到myapi将使用以/api/myapi/开头的请求网址来调用myapi函数。

but if run in the emulator it ends up looking like: /[firebase-project-id]/[firebase-region]/myapi/api/myapi/ 但如果在模拟器中运行,则最终看起来像: /[firebase-project-id]/[firebase-region]/myapi/api/myapi/

This doesn't make a difference if the function doesn't look at the request path but in my case, the function is a handler for an express (koa) handler with routes so knowing the base path is important. 如果该函数不查看请求路径,那么这没有什么区别,但就我而言,该函数是具有路由的Express(koa)处理程序的处理程序,因此了解基本路径很重要。

I've looked to see if anything is available in process.env but only the GCLOUD_PROJECT name and a few FIREBASE_CONFIG params are there. 我一直在查看process.env中是否有任何可用的东西,但是那里只有GCLOUD_PROJECT名称和一些FIREBASE_CONFIG参数。

I could not find any documentation on more advanced control of the rewrite to a function in firebase.json. 我找不到关于在Firebase.json中重写功能的更高级控制的任何文档。

I can work around it in testing by setting an environment variable to match the prefix the functions are running at locally and taking it into account during request handling. 我可以在测试中通过设置环境变量来使其与功能在本地运行的前缀匹配并在请求处理期间将其考虑在内来解决该问题。 Unfortunately the request url prefix is not available until after the emulators are started and the function urls are logged. 不幸的是,直到启动仿真器并记录功能url后,请求url前缀才可用。

I am hoping to find a better solution for testing. 我希望找到更好的测试解决方案。

This turned out to be a bug and is was resolved for my case in firebase-tools 6.10.0. 原来这是一个错误,在firebase-tools 6.10.0中针对我的情况已解决。

https://github.com/firebase/firebase-tools/issues/1279 https://github.com/firebase/firebase-tools/issues/1279

This related issue was also opened: 此相关问题也已打开:

https://github.com/firebase/firebase-tools/issues/1312 https://github.com/firebase/firebase-tools/issues/1312

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有没有办法向正在运行的 firebase 仿真器添加/修改功能? - Is there a way to add/modify functions to a running firebase emulator? 在 firebase 函数中创建 FormData() - Creating FormData() in firebase-functions 在哪里可以找到firebase-admin下所有可用功能的列表? firebase功能? - Where can one find the list of all functions available under firebase-admin? firebase-functions? 仅在满足条件时使用Firebase函数发送通知 - Using Firebase-Functions to Send Notifications Only When A Condition Is Met Firebase 托管不允许我部署 bc firebase-functions 已过时 - Firebase hosting doesn't let me deploy bc firebase-functions is outdated 找不到模块“firebase-functions” - cannot find module "firebase-functions" 部署 firebase 项目时出现错误显示“找不到模块 firebase-functions” - Error shows 'cannot find module firebase-functions' when deploying a firebase project Firebase-functions 部署错误“错误:EACCES:权限被拒绝,打开'/root/.config/configstore/firebase-tools.json'” - Firebase-functions deploy error "Error: EACCES: permission denied, open '/root/.config/configstore/firebase-tools.json'" 拦截 firebase 函数响应(中间件) - intercept firebase-functions response (middleware) firebase-functions 中的 Sendgrid 导入问题 - Sendgrid import issue in firebase-functions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM