繁体   English   中英

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

[英]How to implement nginx proxy_pass in gae standard?

我在我的 GAE 应用程序中使用 firebase-ui-web 进行身份验证。 最近有一个烦人的问题,Safari 正在阻止第三方 cookies,这会中断登录过程。

最好的解决方案( 此处描述)似乎是使用 nginx 实施反向代理配置。以下是详细信息:

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

是否有可能在我们无法添加 nginx 规则的 GAE 中完成同样的事情? 如果重要的话,我正在使用 Python3/Flask。

通过一些谷歌搜索,我想出了这个:

@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

虽然我不确定来源是否良好,但欢迎提供反馈。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM