Peter Nixey
Peter Nixey

Reputation: 16565

How would you create a reverse proxy using a Firebase function?

I'd like to create a reverse proxy for my analytics so that it doesn't get shut down by ad blockers.

Cloudflare has an excellent API for this using their web-workers but using them in conjuction with a CNAME (i.e. on your own host) is only available on their enterprise plan.

The cloudflare code to do the reverse proxy is simply:


addEventListener("fetch", event => {
  event.respondWith(handleRequest(event.request))
})

async function handleRequest(request) {
    request = new Request(request)
    var url = new URL(request.url)
    url.hostname = 'api-js.mixpanel.com'
    return await fetch(url, request)
}

How might one go about creating the same type of functionality using a Firebase function instead?

Upvotes: 0

Views: 712

Answers (1)

CaptainZero
CaptainZero

Reputation: 1501

If you are specifically trying to proxy MixPanel requests to avoid Ad Blockers then you can do this via 2 methods

  1. You can use Cloudflare Zaraz + Cloudflare Worker
  2. You can use their official proxy, that can be hosted in Cloud Run or DigitalOcean droplet: https://github.com/mixpanel/tracking-proxy

Upvotes: 1

Related Questions