Rob--W / cors-anywhere

CORS Anywhere is a NodeJS reverse proxy which adds CORS headers to the proxied request.
MIT License
8.57k stars 5.99k forks source link

TypeError: cors_proxy.emit is not a function [Firebase Functions] #430

Closed peter-palmer closed 2 years ago

peter-palmer commented 2 years ago

I have deployed in Firebase Functions, calling the function by HTTP, but I'm getting this error:

image

index.js

const functions = require("firebase-functions");
const cors_proxy = require("cors-anywhere");

const options = {
   originWhitelist: [], // Allow all origins
   requireHeader: ["origin", "x-requested-with"],
};

cors_proxy.createServer(options);

exports.corsProxyRequest = functions.https.onRequest((req, res) => {
   req.url = req.url.replace("/corsProxyRequest/https:/", "/https://");
   cors_proxy.emit("request", req, res);
});

firebase.json

{
   "rewrites": [
      {
         "source": "**",
         "function": "corsProxyRequest"
      }
   ]
}

When I make a call...

image
Rob--W commented 2 years ago

The emit method is defined on the return value of createServer. But you're trying to use it on the cors_proxy object instead.

It looks like your snippet is based on #160, except modified to be broken.