angularjs - Firebase Functions cors -


i using firebase functions , worked intended when using ionic native http plugin (https://ionicframework.com/docs/native/http/). today, decided move towards angular-http implementation, since can test code in browser too.

the issue facing is, since moved away native approach , using angular way deal http, error related cors:

no 'access-control-allow-origin' header present on requested resource. origin 'http://localhost:8100' therefore not allowed access. response had http status code 500.

on serverside followed https://github.com/firebase/functions-samples/tree/master/authorized-https-endpoint , worked fine, until using angular http.

my code on server looks follows:

const admin = require('firebase-admin'); const cors = require('cors')({origin: true}); admin.initializeapp(functions.config().firebase);  const router = new express.router(); router.use(cors); router.use(validatefirebaseidtoken); router.post('/', (req, res) => {   console.log("proccess myfunction");   ... } exports.myfunction = functions.https.onrequest(router);  

inside firebase console, following log:

3:41:28.429 nachm. warning myfunction typeerror: cannot read property 'apply' of undefined @ immediate. (/user_code/node_modules/express/lib/router/index.js:635:14) @ runcallback (timers.js:639:20) @ tryonimmediate (timers.js:610:5) @ processimmediate [as _immediatecallback] (timers.js:582:5)

3:41:28.428 nachm. warning myfunction uncaught exception

3:41:28.424 nachm. info myfunction proccess myfunction

so looks like,my function being called , log appears, connection gets lost somewhere between. mentioned, worked fine before used angular http. according additional log entries, crash happens somewhere @ moment, when try access firebase storage (but since worked before, pretty sure, access storage fine).

edit: values in body seem undefined too.

console.log("id "+req.body.userid); 

prints:

"id undefined"

okay, found issue. on requesting side, had use 'application/json' content-type. not sure why raised cors error, , why worked way before.


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -