简体   繁体   English

您将如何使用 Firebase function 创建反向代理?

[英]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 (ie on your own host) is only available on their enterprise plan. Cloudflare 有一个很好的 API 用于此使用他们的网络工作者,但将它们与 CNAME 结合使用(即在您自己的主机上)仅在他们的企业计划中可用。

The cloudflare code to do the reverse proxy is simply:做反向代理的 cloudflare 代码很简单:


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? go 如何使用 Firebase function 来创建相同类型的功能?

If you are specifically trying to proxy MixPanel requests to avoid Ad Blockers then you can do this via 2 methods如果您专门尝试代理 MixPanel 请求以避免广告拦截器,那么您可以通过 2 种方法执行此操作

  1. You can use Cloudflare Zaraz + Cloudflare Worker您可以使用 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您可以使用他们的官方代理,可以托管在 Cloud Run 或 DigitalOcean droplet 中: https://github.com/mixpanel/tracking-proxy

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 你如何将model的用户和Firebase中的朋友收藏起来? - How would you model a collection of users and friends in Firebase? 如何在 Rails 中使用反向代理服务 sitemap.xml? - How to serve a sitemap.xml using reverse proxy in rails? 你将如何使用 gcp 和 Go 设计视频上传系统? - How would you design a video upload system using gcp and Go? 如何通过 Firebase Admin 针对代理连接到 Firebase? - How to connect to Firebase by Firebase Admin against a proxy? 你如何对用 express 包装的 firebase 函数进行单元测试? - How do you unit test a firebase function wrapped with express? 如何使用带有 Firebase Cloud Function 的 MongoDB(监视集合?)创建 Flutter Stream - How to create a Flutter Stream using MongoDB (watch collection?) with Firebase Cloud Function 在 Unity 中,如何调用 firebase 异步 function 并将值返回给调用 function? - In Unity how do you call a firebase async function and return the value to a calling function? 我 go 如何使用 flutter 在 Firebase 的 Stripe 扩展中创建产品? - How would I go about creating a product in the Stripe extension in Firebase using flutter? 您是否需要创建一个单独的集合/文档来读取带有 firebase 云 function 的聚合文档 - do you need to create a separate collection/document for reading an aggregated document with firebase cloud function 您如何使用 Jest 模拟 Firebase Firestore 方法? - How do you mock Firebase Firestore methods using Jest?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM