В настоящее время я пытаюсь создать облачную функцию 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 don ' не дает никакого ответа, но он должен вернуть мне "TOTO" ...
Когда я проверяю логи, выполняется console.log ("GET TOTO"), поэтому я не понимаю, почему Res return не отправляется обратно моему клиенту 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
. 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
}
Я пытался добавить возврат, нет возврата, асин c, нет асин c ... но я не понимаю
Спасибо.