I am try use firebase functions in angular application. I use angularfire2 library In result:
{err: Error: Response is not valid JSON object. at new HttpsErrorImpl (http://localhost:4200/vendor.j…}
const functions = require('firebase-functions');
const cors = require('cors')({
origin: true
});
exports.helloWorld = functions.https.onRequest((request, response) => {
cors(request, response, () => {
response.send('Hello from Firebase!');
});
});
import { Component, OnInit } from '@angular/core';
import { AngularFireFunctions } from 'angularfire2/functions';
import { Observable } from 'rxjs';
import { first } from 'rxjs/operators';
@Component({
selector: 'app-test',
templateUrl: './test.component.html',
styleUrls: ['./test.component.css']
})
export class TestComponent implements OnInit {
message: Observable<string>;
message2: string;
constructor(private fns: AngularFireFunctions) {
}
ngOnInit() {
}
getfsf() {
this.fns.httpsCallable('helloWorld')({ text: 'Some Request Data' })
.pipe(first())
.subscribe(resp => {
console.log({ resp });
}, err => {
console.error({ err });
});
}
}
The engines field is required; it must specify one of the supported Node. js versions in order for you to deploy and run functions. Currently firebase init functions sets this field to 16 .
onRequest creates a standard API endpoint, and you'll use whatever methods your client-side code normally uses to make. HTTP requests to interact with them. onCall creates a callable. Once you get used to them, onCall is less effort to write, but you don't have all the flexibility you might be used to.
This is how I was able to fix it.
exports.helloWorld = functions.https.onRequest((request, response) => {
response.send({ "data": "Hello from Firebase!" });
})
It's weird that we need to do it, but it works!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With