Firebase-带路由器的https触发云功能不回复响应

时间:2020-02-07 10:35:38

标签: node.js firebase

我目前正在尝试使用路由创建firebase云功能。

以下是简单的代码:

const functions = require('firebase-functions');
const express = require('express');

// Create an Express object and routes (in order)
const app = express();

app.get('/TOTO', (req, res) => {
  console.log("GET TOTO")
  res.status(200).send("TOTO")
})


// Set our GCF handler to our Express app.
exports.work = functions.https.onRequest(app);

当我执行它时,curl没有给出任何响应,但是它应该返回我“ TOTO” ...

当我检查日志时,会执行console.log(“ GET TOTO”),所以我不明白为什么返回的资源没有发送回我的curl客户端...

这里是日志:

2020-02-07T10:18:41.371688612Z D work: Function execution started
2020-02-07T10:18:41.378Z I work: GET TOTO
2020-02-07T10:18:41.379530391Z D work: Function execution took 8 ms, finished with status code: 200

这是卷发:

curl  -H "Authorization: bearer $(gcloud auth print-identity-token)"  -H "Content-Type:application/json" -XGET "https://${CLOUDFUNCTION_URL}/work/TOTO" -D -

和响应

HTTP/1.1 200 Connection established
HTTP/2 200 
content-type: text/html; charset=utf-8
etag: W/"4-7vr2vtrI8PWK9QfOP94qG3exzYk"
function-execution-id: pnbz2w7zg1zk
x-powered-by: Express
x-cloud-trace-context: 8d739b31bd309bffb0ecb9294e12028d;o=1
date: Fri, 07 Feb 2020 10:32:36 GMT
server: Google Frontend
content-length: 4
alt-svc: quic=":443"; ma=2592000; v="46,43",h3-Q050=":443"; ma=2592000,h3-Q049=":443"; HTTP/1.1 200 Connection established

Node js运行时:nodejs8

package.json:

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "lint": "eslint .",
    "serve": "firebase serve --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "8"
  },
  "dependencies": {
    "express": "^4.17.1",
    "firebase-admin": "^8.6.0",
    "firebase-functions": "^3.3.0",
  },
  "devDependencies": {
    "eslint": "^5.12.0",
    "eslint-plugin-promise": "^4.0.1",
    "firebase-functions-test": "^0.1.6"
  },
  "private": true
}

我试图添加返回,不返回,异步,不异步...但我不知道

谢谢。

1 个答案:

答案 0 :(得分:0)

问题是我的zsh ...卷曲之后,它立即用下一个提示覆盖sdout中的主体响应...

使用bash,没问题。

相关问题