Why is URL rewriting in GAE discouraged?

时间:2016-02-12 20:36:16

标签: java google-app-engine url-rewriting

I'm using Google App Engine with Java runtime. I'm not too clear about the routing policy Google is enforcing. And web searches have only yielded misleading and discordant results in my case. According to Google documentation:

App Engine runs multiple instances of your application, each instance has its own web server for handling requests. Any request can be routed to any instance, so consecutive requests from the same user are not necessarily sent to the same instance. The number of instances can be adjusted automatically as traffic changes.

That's pretty clear. And it lets me think that URL rewriting I define in my development server will be applied after this higher level routing, meaning when a request actually reaches one of the many potentially available app server instances. However, I then stumbled upon a thread in which it's argued that URL rewrite using the Tuckey's URL Rewrite plugin is troublesome in that it cuts out Google's content delivery network for so-called static files.

So my questions are: - Given that the request gets to the server after being routed, what's the matter of rewriting the URL? Server level rewriting shouldn't have any impact on the top level Google's routing. - Google says that static files are stored in different servers having nothing to do with the real application, so you basically don't know there they are. Does this means that if a request for one of these static files comes in, the actual resource is requested to one of these reserved servers and only other requests (including missing resources and invalid URLs coming from pushstate) actually reaches my app's server instances?

It all this was true, I wouldn't see any real performance risk in rewriting URLs at server instance level.

1 个答案:

答案 0 :(得分:0)

执行服务器端重写没有任何问题。

Google使用谷歌前端提供静态文件(在appengine-web.xml中配置),这是一个低延迟,边缘缓存的cdn,所以你应该总是喜欢让它为你提供静态内容,而不是生成或从你的战争服务。它更快,更便宜,并且没有实例扩展的缺点(即用户等待启动)

在您的情况下(angular.html的index.html),您不需要重写,您可以将相同的servlet /资源映射到所有路径,例如/ *

当可能的web.xml路径规则不够灵活,无法将路由映射到servlet时,Tucky重写就会发挥作用。但如果需要,使用它没有问题。