App Engine:重定向到最新版本

App Engine: Redirect to latest version

我想将我的测试用户重定向到我的应用引擎应用程序的最新版本。我听说您可以使用 url latest-dot-project-id.appspot.com 访问最新版本,但这仅适用于默认版本。

任何关于如何重定向到最新版本的想法,它可能有 url version-dot-project-id.appspot.com?

我知道我可以访问 API 以获取最新版本,但我也无法使用服务帐户从那里获取数据。

AFAIK,应用程序无法以编程方式访问可用版本,因此弄清楚 "latest" 版本需要您提供的是保留名称。 test怎么样?使用 version: test 上传要测试的版本,让您的测试人员点击它。然后,当您想使用测试版本上线时,使用 "real" 版本再次上传,然后将其设为默认版本。假设您没有做任何更改,第二次上传应该会很快。

FWIW,许多人为他们的测试版本使用完全独立的应用程序名称,这样测试人员就不会修改生产数据。

如果测试用户不是预先定义的组,他们必须积极地 return 反馈,而 needed/desired 是一种在监控日志等的同时在一段时间内缓慢推出功能的方法,您可以利用 App Engine's traffic splitting functionality. This can be found on the versions page of your app engine's project page in the cloud developer console

可以根据 cookie 或 ip 地址拆分流量。不过,其中任何一个都有一些小怪癖,可以很容易地解决。

You must choose whether to split the traffic by IP address or an HTTP cookie. It's easier to set up an IP address split, but a cookie split is more precise.

更多关于流量拆分的信息here

最终使用 Google App Engine Admin API 获取最新版本。

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL,"https://appengine.googleapis.com/v1beta4/apps/-----/modules/default/versions");
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            $headers = array();
            $headers[] = 'Authorization: Bearer '.json_decode($client->getAccessToken())->access_token;

            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

            $versions = json_decode(curl_exec ($ch))->versions;
            curl_close ($ch);

            $newest_version = "0";
            foreach($versions as $version){
                if(str_replace("-", "", $version->id) > str_replace("-", "", $newest_version)){
                    $newest_version = $version->id;
                }
            }

应该能够使用通用的latest关键字(而不是找出该模块的哪个特定版本是最新的)来到达您需要的任何模块:

latest-dot-<modulename>-dot-<appname>.appspot.com

至少在 python 有效...

latest-dot-project-id.appspot.com 构造中,您没有指定模块名称,这可能是您只点击 default 模块的原因。

Routing via URL doc

中有更多详细信息