[英]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 种方法执行此操作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.