【发布时间】:2020-11-16 19:21:51
【问题描述】:
我有一个 Angular 网站,我正在尝试将云功能集成为 Expressjs。只有云功能可以正常工作。当我访问 http://localhost:5001/project_id/us-central1/app 时,我可以看到控制台输出。但是对于 Angular,它不起作用。
这是尝试使用 angular 时的输出:
hosting: 127.0.0.1 - - [16/Nov/2020:18:57:01 +0000] "GET /favicon.ico HTTP/1.1" 200 4286 "http://localhost:5000/payment" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36"
函数/index.js:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
const express = require('express');
const app = express();
app.get('/', (req, res) => {
console.log("Hello");
});
exports.app = functions.https.onRequest(app);
app.module.ts:
...
providers: [UserService, AngularFireAuthGuard,
{ provide: ORIGIN,useValue: 'http://localhost:5001' },
{ provide: REGION, useValue: 'us-central1' }],
...
firebase.json:
{
"hosting": {
"public": "dist/user",
"ignore": [
"firebase.json",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"function": "app",
"destination": "/index.html"
}
]
},
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"functions": {
"source": "functions"
}
}
payment.component.ts(我尝试调用云函数):
constructor(private _fb: FormBuilder, private router: Router, private fns: AngularFireFunctions) {
const callable = fns.httpsCallable('app');
var data = callable({ name: 'some-data' });
data.subscribe(async res => {
console.log(res);
});
}
【问题讨论】:
-
您还没有从 index.js 中导出任何内容。我建议查看文档。 firebase.google.com/docs/functions/…
-
@DougStevenson 我导出了,但我错过了那部分,抱歉。我编辑了第一篇文章。
标签: angular firebase google-cloud-functions