Rob--W/cors-anywhere

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

peter-palmer opened this issue · 1 comments

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

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.