在Google App Engine中处理/_ah/start路由NodeJ [英] Handling /_ah/start route NodeJs at Google App Engine

查看:106
本文介绍了在Google App Engine中处理/_ah/start路由NodeJ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的NodeJs应用程序使用 Google App Engine 标准环境. 一切正常,直到我在快速应用程序中注册了路由"/*"以捕获我的初始路由(例如"/","/login"等)之后的所有路由.在GAE上部署我的应用程序后,我得到了:

I am using Google App Engine Standard Environment for my NodeJs App. Things were working fine until I register a route '/*' in my express app to catch all routes after my initial routes like '/', '/login' etc. . After deploying my app on GAE I got :

Error: Server Error
The server encountered an error and could not complete your request.
Please try again in 30 seconds.

在我的App Engine构建日志中:

In my App Engine build logs :

我的app.yaml看起来像: app.yaml

My app.yaml looks like: app.yaml

runtime: nodejs10
env: standard
service: default
health_check:
  enable_health_check: False
manual_scaling:
  instances: 1
resources:
  cpu: 1
  memory_gb: 0.5
  disk_size_gb: 10

GAE官方文档中的语录: https://cloud.google.com /appengine/docs/standard/nodejs/how-instances-are-managed

Quoting from official Docs of GAE: https://cloud.google.com/appengine/docs/standard/nodejs/how-instances-are-managed

启动 创建每个服务实例以响应启动请求,该启动请求是对/_ah/start的空HTTP GET请求. App Engine发送此请求以使实例存在.用户无法将请求发送到/_ah/start.手动和基本伸缩实例必须先响应启动请求,然后才能处理其他请求.启动请求可以用于两个目的:

Startup Each service instance is created in response to a start request, which is an empty HTTP GET request to /_ah/start. App Engine sends this request to bring an instance into existence; users cannot send a request to /_ah/start. Manual and basic scaling instances must respond to the start request before they can handle another request. The start request can be used for two purposes:

启动无限期运行的程序,无需进一步接受 要求.在实例收到其他实例之前对其进行初始化 交通.手动,基本和自动扩展实例启动 不一样.启动手动扩展实例时,App Engine 立即向每个实例发送一个/_ah/start请求.当你 启动基本扩展服务的实例,App Engine允许它 接受流量,但/_ah/start请求未发送到实例 直到收到第一个用户请求.多种基本缩放 实例仅在必要时启动,以便处理增加的 交通.自动缩放实例不会收到任何/_ah/start 请求.

To start a program that runs indefinitely, without accepting further requests. To initialize an instance before it receives additional traffic. Manual, basic, and automatically scaling instances startup differently. When you start a manual scaling instance, App Engine immediately sends a /_ah/start request to each instance. When you start an instance of a basic scaling service, App Engine allows it to accept traffic, but the /_ah/start request is not sent to an instance until it receives its first user request. Multiple basic scaling instances are only started as necessary, in order to handle increased traffic. Automatically scaling instances do not receive any /_ah/start request.

当实例使用HTTP响应/_ah/start请求时 状态码200–299或404,则认为已成功 已启动并可以处理其他请求.否则,App Engine 终止实例.手动扩展实例重新启动 立即,而基本扩展实例仅在以下情况下重新启动: 服务流量所需.

When an instance responds to the /_ah/start request with an HTTP status code of 200–299 or 404, it is considered to have successfully started and can handle additional requests. Otherwise, App Engine terminates the instance. Manual scaling instances are restarted immediately, while basic scaling instances are restarted only when needed for serving traffic.

我错过了什么吗?请帮忙.

Am I missing something? Please help.

预先感谢

推荐答案

我通过将我的最后一条路线注册为这样来解决了这个问题:

I solved this problem by registering my last route as this:

app.get(/^(?!.*_ah).*$/,(req,res,next)=>{
})

与我以前的配置相比.

app.get('/*',(req,res,next)=>{
    })

在这里我使用了否定正则表达式. 对此SO答案的信用

引用GAE官方文档

在实例收到其他流量之前对其进行初始化.手动,基本和自动扩展实例的启动方式有所不同.启动手动扩展实例时,App Engine会立即向每个实例发送/_ah/start请求.

To initialize an instance before it receives additional traffic. Manual, basic, and automatically scaling instances startup differently. When you start a manual scaling instance, App Engine immediately sends a /_ah/start request to each instance.

上述路由处理程序所做的是捕获除_ah开头的路由以外的所有路由,这意味着_ah/start和_ah/stop将不会被我的应用程序监听,因为它们被Google App引擎用于注册该应用程序.

What above route handler does is to catch all routes except the one starting with _ah that means _ah/start and _ah/stop will not be listened by my app as they are used by Google App engine for registering the app.

我希望这对以后的人有所帮助.

I hope this helps someone in the future.

谢谢

这篇关于在Google App Engine中处理/_ah/start路由NodeJ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆