如何在gae标准中实现nginx proxy_pass?

jvidinwx  于 2022-12-11  发布在  Nginx
关注(0)|答案(1)|浏览(172)

I'm using firebase-ui-web for authentication in my GAE app. There is an annoying issue recently where Safari is blocking 3rd party cookies and this breaks the login process.
The best solution (described here) seems to be implement a reverse-proxy config with nginx. Here are the details:

# reverse proxy for signin-helpers for popup/redirect sign in.
location /__/auth {
  proxy_pass https://<project>.firebaseapp.com;
}

Is it possible to accomplish the same thing in GAE where we are not able to add nginx rules? I'm using Python3/Flask if it matters.

guicsvcw

guicsvcw1#

我在谷歌上搜索了一下,找到了这个:

@app.route('/<path:path>', methods=['GET', 'POST'])
def proxy(path):
    url = f'https://www.example.com/{path}'
    excluded_headers = ['content-encoding', 'content-length', 
                        'transfer-encoding', 'connection']

    if request.method == 'GET':
        resp = requests.get(url)
    elif request.method == 'POST':
        resp = requests.post(url, data=request.form)

    headers = [(name, value) for (name, value) in resp.raw.headers.items() 
        if name.lower() not in excluded_headers]
    response = Response(resp.content, resp.status_code, headers)
    return response

虽然我不相信来源是好的,所以欢迎反馈。

相关问题