如何在不启动函数模拟器的情况下指定函数模拟器的主机:端口

Mic*_*fin 5 firebase google-cloud-firestore

我正在用 Go 编写云函数并从 firestore 模拟器触发它们。如果我手动启动 firestore 模拟器,这将有效:

\n
 java -jar ~/.cache/firebase/emulators/cloud-firestore-emulator-v1.11.9.jar \\\n  --functions_emulator localhost:5001\n
Run Code Online (Sandbox Code Playgroud)\n

然后我在 localhost:5001 上启动自己的服务器来处理触发的函数,一切似乎都正常。

\n

但是,我想以正常方式启动 firestore 模拟器,以便获得漂亮的 Web UI 等。我的 firebase.json 文件如下:

\n
 java -jar ~/.cache/firebase/emulators/cloud-firestore-emulator-v1.11.9.jar \\\n  --functions_emulator localhost:5001\n
Run Code Online (Sandbox Code Playgroud)\n

我使用启动模拟器

\n
{\n  "emulators": {\n    "firestore": {\n      "port": 8080\n    },\n    "functions": {\n      "port": 5001\n    },\n    "pubsub": {\n      "port": 8085\n    },\n    "ui": {\n      "enabled": true\n    },\n    "hosting": {\n      "port": 5000\n    },\n    "auth": {\n      "port": 9099\n    }\n  },\n  "ui": {\n    "enabled": true,\n    "host": "localhost",\n    "port": 4000\n  },\n  "functions": {\n    "port": "5001",\n    "predeploy": [\n      "npm --prefix \\"$RESOURCE_DIR\\" run lint",\n      "npm --prefix \\"$RESOURCE_DIR\\" run build"\n    ],\n    "source": "functions"\n  },\n  "pubsub": {\n    "port": "8085"\n  },\n  "firestore": {\n    "rules": "firestore.rules",\n    "indexes": "firestore.indexes.json"\n  },\n  "hosting": {\n    "public": "build",\n    "ignore": [\n      "firebase.json",\n      "**/.*",\n      "**/node_modules/**"\n    ],\n    "rewrites": [\n      {\n        "source": "**",\n        "destination": "/index.html"\n      }\n    ]\n  }\n}\n\n
Run Code Online (Sandbox Code Playgroud)\n

然后我使用以下命令在 firestore 上设置触发器:

\n
firebase emulators:start --only firestore\n
Run Code Online (Sandbox Code Playgroud)\n

最后,我在/Requests下手动创建一个文档。firestore-debug.log 现在包含:

\n
[debug] [2020-11-10T21:09:20.187Z] ----------------------------------------------------------------------\n[debug] [2020-11-10T21:09:20.189Z] Command:       /usr/local/Cellar/node/12.4.0/bin/node /Users/michaelcoffin/node_modules_global/bin/firebase emulators:start --only firestore\n[debug] [2020-11-10T21:09:20.189Z] CLI Version:   8.15.0\n[debug] [2020-11-10T21:09:20.189Z] Platform:      darwin\n[debug] [2020-11-10T21:09:20.189Z] Node Version:  v12.4.0\n[debug] [2020-11-10T21:09:20.190Z] Time:          Tue Nov 10 2020 13:09:20 GMT-0800 (Pacific Standard Time)\n[debug] [2020-11-10T21:09:20.190Z] ----------------------------------------------------------------------\n[debug] [2020-11-10T21:09:20.190Z] \n[debug] [2020-11-10T21:09:20.197Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]\n[debug] [2020-11-10T21:09:20.197Z] > authorizing via signed-in user\n[info] i  emulators: Starting emulators: firestore {"metadata":{"emulator":{"name":"hub"},"message":"Starting emulators: firestore"}}\n[debug] [2020-11-10T21:09:20.210Z] [hub] writing locator at /var/folders/xy/m2rx3tw14mnfvryxx2jvhyjh0000gn/T/hub-fugalist.json\n[debug] [2020-11-10T21:09:20.229Z] Ignoring unsupported arg: projectId {"metadata":{"emulator":{"name":"firestore"},"message":"Ignoring unsupported arg: projectId"}}\n[debug] [2020-11-10T21:09:20.229Z] Ignoring unsupported arg: auto_download {"metadata":{"emulator":{"name":"firestore"},"message":"Ignoring unsupported arg: auto_download"}}\n[debug] [2020-11-10T21:09:20.229Z] Starting Firestore Emulator with command {"binary":"java","args":["-Duser.language=en","-jar","/Users/michaelcoffin/.cache/firebase/emulators/cloud-firestore-emulator-v1.11.9.jar","--host","localhost","--port",8080,"--rules","/Users/michaelcoffin/expmap/fe/firestore.rules"],"optionalArgs":["port","webchannel_port","host","rules","functions_emulator","seed_from_export"],"joinArgs":false} {"metadata":{"emulator":{"name":"firestore"},"message":"Starting Firestore Emulator with command {\\"binary\\":\\"java\\",\\"args\\":[\\"-Duser.language=en\\",\\"-jar\\",\\"/Users/michaelcoffin/.cache/firebase/emulators/cloud-firestore-emulator-v1.11.9.jar\\",\\"--host\\",\\"localhost\\",\\"--port\\",8080,\\"--rules\\",\\"/Users/michaelcoffin/expmap/fe/firestore.rules\\"],\\"optionalArgs\\":[\\"port\\",\\"webchannel_port\\",\\"host\\",\\"rules\\",\\"functions_emulator\\",\\"seed_from_export\\"],\\"joinArgs\\":false}"}}\n[info] i  firestore: Firestore Emulator logging to firestore-debug.log {"metadata":{"emulator":{"name":"firestore"},"message":"Firestore Emulator logging to \\u001b[1mfirestore-debug.log\\u001b[22m"}}\n[debug] [2020-11-10T21:09:21.040Z] API endpoint: http:// {"metadata":{"emulator":{"name":"firestore"},"message":"API endpoint: http://"}}\n[debug] [2020-11-10T21:09:21.040Z] localhost:8080\nIf you are using a library that supports the FIRESTORE_EMULATOR_HOST environment variable, run:\n\n   export FIRESTORE_EMULATOR_HOST=localhost:8080\n\nDev App Server is now running.\n\n {"metadata":{"emulator":{"name":"firestore"},"message":"localhost:8080\\nIf you are using a library that supports the FIRESTORE_EMULATOR_HOST environment variable, run:\\n\\n   export FIRESTORE_EMULATOR_HOST=localhost:8080\\n\\nDev App Server is now running.\\n\\n"}}\n[warn] \xe2\x9a\xa0  ui: Emulator UI unable to start on port 4000, starting on 4003 instead. {"metadata":{"emulator":{"name":"ui"},"message":"Emulator UI unable to start on port 4000, starting on 4003 instead."}}\n[debug] [2020-11-10T21:09:21.275Z] Ignoring unsupported arg: auto_download {"metadata":{"emulator":{"name":"ui"},"message":"Ignoring unsupported arg: auto_download"}}\n[debug] [2020-11-10T21:09:21.275Z] Ignoring unsupported arg: port {"metadata":{"emulator":{"name":"ui"},"message":"Ignoring unsupported arg: port"}}\n[debug] [2020-11-10T21:09:21.275Z] Starting Emulator UI with command {"binary":"node","args":["/Users/michaelcoffin/.cache/firebase/emulators/ui-v1.2.2/server.bundle.js"],"optionalArgs":[],"joinArgs":false} {"metadata":{"emulator":{"name":"ui"},"message":"Starting Emulator UI with command {\\"binary\\":\\"node\\",\\"args\\":[\\"/Users/michaelcoffin/.cache/firebase/emulators/ui-v1.2.2/server.bundle.js\\"],\\"optionalArgs\\":[],\\"joinArgs\\":false}"}}\n[info] i  ui: Emulator UI logging to ui-debug.log {"metadata":{"emulator":{"name":"ui"},"message":"Emulator UI logging to \\u001b[1mui-debug.log\\u001b[22m"}}\n[debug] [2020-11-10T21:09:21.369Z] Web / API server started at http://localhost:4003\n {"metadata":{"emulator":{"name":"ui"},"message":"Web / API server started at http://localhost:4003\\n"}}\n[info] \n\xe2\x94\x8c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x90\n\xe2\x94\x82 \xe2\x9c\x94  All emulators ready! View status and logs at http://localhost:4003 \xe2\x94\x82\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x98\n\n\xe2\x94\x8c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xac\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xac\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x90\n\xe2\x94\x82 Emulator  \xe2\x94\x82 Host:Port      \xe2\x94\x82 View in Emulator UI             \xe2\x94\x82\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xbc\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xbc\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xa4\n\xe2\x94\x82 Firestore \xe2\x94\x82 localhost:8080 \xe2\x94\x82 http://localhost:4003/firestore \xe2\x94\x82\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xb4\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xb4\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x98\n  Other reserved ports: 4400, 4500\n\nIssues? Report them at https://github.com/firebase/firebase-tools/issues and attach the *-debug.log files.\n \n[debug] [2020-11-10T21:09:24.814Z] Nov 10, 2020 1:09:24 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead\nINFO: Detected non-HTTP/2 connection.\nNov 10, 2020 1:09:24 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead\nINFO: Detected non-HTTP/2 connection.\n {"metadata":{"emulator":{"name":"firestore"},"message":"Nov 10, 2020 1:09:24 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead\\nINFO: Detected non-HTTP/2 connection.\\nNov 10, 2020 1:09:24 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead\\nINFO: Detected non-HTTP/2 connection.\\n"}}\n[debug] [2020-11-10T21:09:24.814Z] Nov 10, 2020 1:09:24 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead\nINFO: Detected non-HTTP/2 connection.\n {"metadata":{"emulator":{"name":"firestore"},"message":"Nov 10, 2020 1:09:24 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead\\nINFO: Detected non-HTTP/2 connection.\\n"}}\n[debug] [2020-11-10T21:09:24.944Z] Nov 10, 2020 1:09:24 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead\nINFO: Detected HTTP/2 connection.\n {"metadata":{"emulator":{"name":"firestore"},"message":"Nov 10, 2020 1:09:24 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead\\nINFO: Detected HTTP/2 connection.\\n"}}\n[debug] [2020-11-10T21:09:25.386Z] Nov 10, 2020 1:09:25 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead\nINFO: Detected non-HTTP/2 connection.\n {"metadata":{"emulator":{"name":"firestore"},"message":"Nov 10, 2020 1:09:25 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead\\nINFO: Detected non-HTTP/2 connection.\\n"}}\n[debug] [2020-11-10T21:09:32.373Z] Nov 10, 2020 1:09:32 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead\nINFO: Detected non-HTTP/2 connection.\n {"metadata":{"emulator":{"name":"firestore"},"message":"Nov 10, 2020 1:09:32 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead\\nINFO: Detected non-HTTP/2 connection.\\n"}}\n[debug] [2020-11-10T21:09:40.867Z] Nov 10, 2020 1:09:40 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead\nINFO: Detected non-HTTP/2 connection.\n {"metadata":{"emulator":{"name":"firestore"},"message":"Nov 10, 2020 1:09:40 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead\\nINFO: Detected non-HTTP/2 connection.\\n"}}\n[debug] [2020-11-10T21:09:41.511Z] Nov 10, 2020 1:09:41 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead\nINFO: Detected non-HTTP/2 connection.\n {"metadata":{"emulator":{"name":"firestore"},"message":"Nov 10, 2020 1:09:41 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead\\nINFO: Detected non-HTTP/2 connection.\\n"}}\n[debug] [2020-11-10T21:09:41.521Z] Nov 10, 2020 1:09:41 PM com.google.cloud.datastore.emulator.impl.context.EmulatorAuthorization warnAboutSecuredJwt\nWARNING: expected an unsecured JWT, the emulator does not validate JWTs and IS NOT SECURE\n {"metadata":{"emulator":{"name":"firestore"},"message":"Nov 10, 2020 1:09:41 PM com.google.cloud.datastore.emulator.impl.context.EmulatorAuthorization warnAboutSecuredJwt\\nWARNING: expected an unsecured JWT, the emulator does not validate JWTs and IS NOT SECURE\\n"}}\n[debug] [2020-11-10T21:09:41.629Z] Nov 10, 2020 1:09:41 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead\nINFO: Detected non-HTTP/2 connection.\n {"metadata":{"emulator":{"name":"firestore"},"message":"Nov 10, 2020 1:09:41 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead\\nINFO: Detected non-HTTP/2 connection.\\n"}}\n[debug] [2020-11-10T21:10:21.137Z] Nov 10, 2020 1:10:21 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead\nINFO: Detected non-HTTP/2 connection.\n {"metadata":{"emulator":{"name":"firestore"},"message":"Nov 10, 2020 1:10:21 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead\\nINFO: Detected non-HTTP/2 connection.\\n"}}\n[debug] [2020-11-10T21:10:21.165Z] Nov 10, 2020 1:10:21 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead\nINFO: Detected non-HTTP/2 connection.\n {"metadata":{"emulator":{"name":"firestore"},"message":"Nov 10, 2020 1:10:21 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead\\nINFO: Detected non-HTTP/2 connection.\\n"}}\n[debug] [2020-11-10T21:10:21.179Z] Nov 10, 2020 1:10:21 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead\nINFO: Detected non-HTTP/2 connection.\n {"metadata":{"emulator":{"name":"firestore"},"message":"Nov 10, 2020 1:10:21 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead\\nINFO: Detected non-HTTP/2 connection.\\n"}}\n[debug] [2020-11-10T21:10:21.225Z] Nov 10, 2020 1:10:21 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead\nINFO: Detected non-HTTP/2 connection.\n {"metadata":{"emulator":{"name":"firestore"},"message":"Nov 10, 2020 1:10:21 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead\\nINFO: Detected non-HTTP/2 connection.\\n"}}\n[debug] [2020-11-10T21:10:21.239Z] Nov 10, 2020 1:10:21 PM com.google.cloud.datastore.emulator.impl.events.EventLogger publishEvent\nWARNING: Failed to publish event for trigger projects/fugalist/triggers/Requests because Functions Emulator host/port is not configured.\n {"metadata":{"emulator":{"name":"firestore"},"message":"Nov 10, 2020 1:10:21 PM com.google.cloud.datastore.emulator.impl.events.EventLogger publishEvent\\nWARNING: Failed to publish event for trigger projects/fugalist/triggers/Requests because Functions Emulator host/port is not configured.\\n"}}\n\n
Run Code Online (Sandbox Code Playgroud)\n

在我手动创建文档后立即出现的相关部分是最后一个条目:

\n
WARNING: Failed to publish event for trigger projects/fugalist/triggers/Requests because Functions Emulator host/port is not configured.\n {"metadata":{"emulator":{"name":"firestore"},"message":"Nov 10, 2020 1:10:21 PM com.google.cloud.datastore.emulator.impl.events.EventLogger publishEvent\\nWARNING: Failed to publish event for trigger projects/fugalist/triggers/Requests because Functions Emulator host/port is not configured.\\n"}}\n
Run Code Online (Sandbox Code Playgroud)\n

事实上,ps 显示在调用 firestore 模拟器时未使用 --functions_emulator 标志:

\n
michaelcoffin    98802   0.0  1.6 16006468 536636   ??  Ss    1:09PM   0:06.19 /usr/bin/java -Duser.language=en -jar /Users/michaelcoffin/.cache/firebase/emulators/cloud-firestore-emulator-v1.11.9.jar --host localhost --port 8080 --rules /Users/michaelcoffin/expmap/fe/firestore.rules\n
Run Code Online (Sandbox Code Playgroud)\n

事实上,如果您要求功能模拟器,就会使用它:

\n
firebase emulators:start --only firestore,functions\n\nps output:\n99072   0.0  1.2 15892768 391240   ??  Ss    1:41PM   0:04.17 /usr/bin/java -Duser.language=en -jar /Users/michaelcoffin/.cache/firebase/emulators/cloud-firestore-emulator-v1.11.9.jar --host localhost --port 8080 --rules /Users/michaelcoffin/expmap/fe/firestore.rules --functions_emulator localhost:5001\n
Run Code Online (Sandbox Code Playgroud)\n

我知道这并不完全是一个错误,因为模拟器套件并不正式支持用 Go 编写的 Google Cloud Functions。然而,如果我使用 --functions_emulator 标志手动启动 firestore 模拟器,模拟器套件实际上可以与 Go 一起正常工作。因此,我试图找到一种解决方法,以便即使在函数模拟器未启动时也使用 --functions_emulator 标志。

\n

小智 1

Firebase CLI 不提供通过命令设置主机和端口的标志firebase emulators:start。尽管如此,您可以控制文件内所有模拟器的端口设置firebase.json。您应该在其中看到下面的配置,您可以在其中替换端口值:

"emulators": {
    "firestore": {
      "port": 8500
    },
    "ui": {
      "enabled": true,
      "port": 4040
    }
}
Run Code Online (Sandbox Code Playgroud)

关于主机,默认情况下它设置为 localhost,所以这应该不是问题。