我有一个nuxt
应用程序上传到 Firebase(作为云功能)。我还有一个我试图从应用程序调用的可调用函数。问题是它试图调用localhost
url 而不是生产的。
我的 Firebase 设置nuxt.config.js
如下所示:
module.exports = {
env: {
functionsURL: process.env.NUXT_ENV_FUNCTIONS === 'local' ? "http://localhost:5001/turniejomat/us-central1" : 'https://us-central1-turniejomat.cloudfunctions.net', // I would expect this to be applied
},
modules: [
[
'@nuxtjs/firebase',
{
config: {
// app config
},
services: {
functions: {
location: 'us-central1',
emulatorPort: 5001,
}
}
}
]
],
}
firebase.nuxt.org文档仅提及模拟器配置,但未提及生产。
我这样调用函数:
const signUp = await this.$fire.functions.httpsCallable("signup")(configObject)
如何使功能在生产中使用正确的 url?
编辑:
这是package.json
设置:
"scripts": {
"dev": "SET \"NUXT_ENV_FUNCTIONS=local\" & nuxt",
"build": "SET \"NUXT_ENV_FUNCTIONS=fire\" & nuxt build",
}
编辑2:
显然env.functionsURL
应用正确,因为应用程序代码直接将此变量用于其他目的并且它可以正常工作!这是callable functions
唯一一个由于某种原因没有收到要调用的相关生产 url。同时,代码中唯一出现 5001 端口的地方是:
nuxt.config.js / env
环境nuxt.config.js / modules / services / functions / emulatorPort
环境service.functions.js
自动添加的文件夹中的模块nuxt/firebase
(我猜是通过 firebase.nuxtjs 吗?)。
该模块如下所示:
export default async function (session) {
await import('firebase/functions')
const functionsService = session.functions('us-central1')
functionsService.useFunctionsEmulator('http://localhost:5001')
return functionsService
}
所以也许出于某种原因callable function
认为它仍然应该使用模拟器设置?我怎么能阻止它?
调用模块的唯一位置是nuxt/firebase/index.js
,如下所示:
if (process.server) {
servicePromises = [
authService(session, firebase, ctx, inject),
firestoreService(session, firebase, ctx, inject),
functionsService(session, firebase, ctx, inject),
]
}
if (process.client) {
servicePromises = [
authService(session, firebase, ctx, inject),
firestoreService(session, firebase, ctx, inject),
functionsService(session, firebase, ctx, inject),
]
}
这似乎确实不管环境如何,Firebase 的本机代码确实应用了相同的设置。我可以修改functionsService
代码,但它似乎不是最佳解决方案,因为 Firebase 可能会在某些时候覆盖它,例如在构建或更新期间。或者可能是这些“本机”文件仅在开始时生成并且尽管在配置中进行了潜在更改(这是不正确的,但现在是正确的),但并未更新。
我怎样才能强制更改这些 Firebase 的文件以区分 prod 和 dev 环境并使它们安全地持续存在?可能nuxt.config.js / modules / services / functions /
应该配置不同,但是如何?