英文:
Firebase emulator does not show url for function in Getting Started
问题
我正在按照Firebase的入门教程进行操作。一切都已设置好,但当我运行以下命令时:
firebase emulators:start
(在文章中的第7阶段),它说:
> 检查firebase emulators:start命令的输出,查找HTTP函数的URL。它会类似于http://localhost:5001/MY_PROJECT/us-central1/addMessage,
我没有看到URL。我的输出是:
i emulators: Starting emulators: functions, firestore
⚠ functions: The following emulators are not running, calls to these services from the Functions emulator will affect production: auth, database, hosting, pubsub, storage
i firestore: Firestore Emulator logging to firestore-debug.log
✔ firestore: Firestore Emulator UI websocket is running on 9150.
i ui: Emulator UI logging to ui-debug.log
i functions: Watching "/home/jeff/projects/scratch/fs-test/functions" for Cloud Functions...
✔ functions: Using node@18 from host.
✔ functions: Loaded functions definitions from source: .
┌─────────────────────────────────────────────────────────────┐
│ ✔ All emulators ready! It is now safe to connect your app. │
│ i View Emulator UI at http://127.0.0.1:4000/ │
└─────────────────────────────────────────────────────────────┘
┌───────────┬────────────────┬─────────────────────────────────┐
│ Emulator │ Host:Port │ View in Emulator UI │
├───────────┼────────────────┼─────────────────────────────────┤
│ Functions │ 127.0.0.1:5001 │ http://127.0.0.1:4000/functions │
├───────────┼────────────────┼─────────────────────────────────┤
│ Firestore │ 127.0.0.1:8080 │ http://127.0.0.1:4000/firestore │
└───────────┴────────────────┴─────────────────────────────────┘
Emulator Hub running at 127.0.0.1:4400
Other reserved ports: 4500, 9150
Issues? Report them at https://github.com/firebase/firebase-tools/issues and attach the *-debug.log files.
URL在哪里?
我需要运行其他模拟器吗?
英文:
I am following the Firebase Getting Started tutorial. Everything is set up, but when I run
firebase emulators:start
(stage 7 in the article), where it says
> Check the output of the firebase emulators:start command for the URL of the HTTP function. It will look similar to http://localhost:5001/MY_PROJECT/us-central1/addMessage,
I do not see a url. My output is
i emulators: Starting emulators: functions, firestore
⚠ functions: The following emulators are not running, calls to these services from the Functions emulator will affect production: auth, database, hosting, pubsub, storage
i firestore: Firestore Emulator logging to firestore-debug.log
✔ firestore: Firestore Emulator UI websocket is running on 9150.
i ui: Emulator UI logging to ui-debug.log
i functions: Watching "/home/jeff/projects/scratch/fs-test/functions" for Cloud Functions...
✔ functions: Using node@18 from host.
✔ functions: Loaded functions definitions from source: .
┌─────────────────────────────────────────────────────────────┐
│ ✔ All emulators ready! It is now safe to connect your app. │
│ i View Emulator UI at http://127.0.0.1:4000/ │
└─────────────────────────────────────────────────────────────┘
┌───────────┬────────────────┬─────────────────────────────────┐
│ Emulator │ Host:Port │ View in Emulator UI │
├───────────┼────────────────┼─────────────────────────────────┤
│ Functions │ 127.0.0.1:5001 │ http://127.0.0.1:4000/functions │
├───────────┼────────────────┼─────────────────────────────────┤
│ Firestore │ 127.0.0.1:8080 │ http://127.0.0.1:4000/firestore │
└───────────┴────────────────┴─────────────────────────────────┘
Emulator Hub running at 127.0.0.1:4400
Other reserved ports: 4500, 9150
Issues? Report them at https://github.com/firebase/firebase-tools/issues and attach the *-debug.log files.
Where is the url?
Do I need other emulators running?
答案1
得分: 1
我使用了 firebase-tools 版本 12.1.0,并且在我的端上正常运行。我能够在本地仿真器中看到已部署的函数。请见下方日志:
✔ functions: 使用来自主机的 node@18。
✔ functions: 从源加载函数定义:helloWorld。
✔ functions[us-central1-helloWorld]: http 函数已初始化
(http://127.0.0.1:5001/sample-project/us-central1/helloWorld)。
在步骤 4 中,它说“您可以打开源代码目录并按照以下部分的说明开始添加代码”。您是否这样做了?
在您的源代码目录中,尝试打开 index.js 文件并查看是否已经在那里编写了任何函数。在我的情况下,我只是取消了下面的代码片段的注释:
exports.helloWorld = onRequest((request, response) => {
logger.info("Hello logs!", {structuredData: true});
response.send("Hello from Firebase!");
});
您还可以在仿真器用户界面中检查函数日志 - http://127.0.0.1:4000/functions。
英文:
I used firebase-tools version 12.1.0 and it worked fine on my end. I was able to see the deployed function in my local emulator. See logs below:
✔ functions: Using node@18 from host.
✔ functions: Loaded functions definitions from source: helloWorld.
✔ functions[us-central1-helloWorld]: http function initialized
(http://127.0.0.1:5001/sample-project/us-central1/helloWorld).
In step 4, it says "you can open the source directory and start adding code as described in the following sections". Did you do this?
In your source directory, try to open the index.js file and see if you have written any functions there. In my case, I just uncommented the code snippet below:
exports.helloWorld = onRequest((request, response) => {
logger.info("Hello logs!", {structuredData: true});
response.send("Hello from Firebase!");
});
You can also check the function logs in your emulator UI - http://127.0.0.1:4000/functions
答案2
得分: 0
在我的 index.js 文件中,我也遇到了相同的问题!但是我找到了解决方案。
首先,我有类似这样的代码:
exports.app = functions.https.onRequest(app);
module.exports = app;
但后来我注释掉了最后一行:
exports.app = functions.https.onRequest(app);
// module.exports = app;
然后它就正常工作了!
英文:
In my index.js I had the same issue! But I figured out the solution.
First I have something like this:
exports.app = functions.https.onRequest(app);
module.exports = app;
But then I comment the last line:
exports.app = functions.https.onRequest(app);
// module.exports = app;
And it works!
答案3
得分: 0
我猜想你的问题可能是你的函数文件位置。
请注意仿真器告诉你:
✔ functions: 从源加载函数定义:。
这意味着它实际上只从你项目中的“functions”文件夹中找到的文件中加载你定义的函数,但实际上没有加载任何函数,因为该文件夹内没有定义任何函数。
进入“Functions”文件夹,在那里你会找到包含文档中的“Hello World”函数的Index.js文件。使用它,然后再次运行仿真器,它将显示你可以调用该函数的URL。
英文:
I guess your problem is probably your functions file location.
Note that the emulator tells you:
✔ functions: Loaded functions definitions from source: .
Which means that it actually loads the functions you defined only from the files found in the 'functions' folder in your project, but actually it didn't load any function because no function was defined inside that folder.
Enter to 'Functions' folder, where you will find the Index.js file that include 'Hello World' function in the documentation. Use it and then run the emulator again, then it will show you the URL where you can call the function
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论