0

I am trying to parse a RSS feed using the method shown here in my firebase cloud function. I want this function to be triggered when there is a create event in my database. My code is like this:

const functions = require('firebase-functions');
const admin = require('firebase-admin');
const { JSDOM } = require( "jsdom" );
const { window } = new JSDOM( "" );
const $ = require( "jquery" )( window );
admin.initializeApp(functions.config().firebase);

exports.onTest = functions.database.ref('/test/').onCreate((aSnapshot, context) => {
    $.get("https://stackoverflow.com/feeds/question/10943544", function (data) {
            console.log("hello");
        });
    });
    return null;
});

I keep getting the following error: Cross Origin Null Forbidden whenever the function is run. What am I doing wrong?

speedster01
  • 433
  • 3
  • 19
  • It seems that you are facing CORS error - which is expected in case you didn't set this part in your Firebase side - that you can fix by modifying your `firebase.json` file and the plugin in your function. Could you please give it a try making these changes as indicated in this other post [here](https://stackoverflow.com/questions/52266714/firebase-hosting-blocking-script-due-to-cors-issue)? – gso_gabriel Jun 04 '20 at 06:33
  • What should I pass as ```req``` and ```res```? In that question it is a HTTP function but it's not that in my case. – speedster01 Jun 04 '20 at 06:43
  • Hi @speedster01 which language do you pretend to use with your Cloud Function? You will need to send and configure CORS for your application, so, adding the library for example is needed and the rest would depend on how you will be handling it. – gso_gabriel Jun 04 '20 at 12:55
  • @gso_gabriel I am not sure I understood your question. This is a cloud function which I will deploy over node.js. The code I have given is the content of my index.js file. The link you gave also showed the cors library added in the index.js file, but there a HTTP function was used, hence the ```req``` and ```res``` parameters were that of the HTTP function itself. In my case what should it be? – speedster01 Jun 04 '20 at 16:31
  • Thanks for your comment @speedster01 ! It was exactly the information I wanted. Considering your usage, this post [here](https://stackoverflow.com/questions/42755131/enabling-cors-in-cloud-functions-for-firebase), should make more sense, since it's using Cloud Functions with Node.js directly to Realtime Database. – gso_gabriel Jun 05 '20 at 11:50
  • @gso_gabriel the functions in that post are also HTTP triggers and not realtime database triggers. – speedster01 Jun 06 '20 at 13:40
  • If you are facing CORS issue, it's related to the sources of the codes, so the usage of HTTP is required. Please, since this ddn't help you, update your question with more information on your environment and how you are trying to use it. – gso_gabriel Jun 08 '20 at 12:51

0 Answers0