简体   繁体   English

app.yaml:带有static_dir的URL中的通配符?

[英]app.yaml : wildcard in URL with static_dir?

My attempt at matching a regex as directory name in app.yaml doesn't work : 我在app.yaml中将正则表达式作为目录名匹配的尝试不起作用:

- url: /v1_.*
  static_dir: static/v1
  expiration: "364d"

Although this official spec says regex syntax is supported. 虽然这个官方规范说支持正则表达式语法。 Is there a way to make this work ? 有没有办法让这项工作?

Ie /v1_2014-01-29/img/logo.png should match the static file /static/v1/img/logo.png . /v1_2014-01-29/img/logo.png应该与静态文件/static/v1/img/logo.png匹配。

Trivia 琐事

I use Google App Engine to serve a Go webapp. 我使用Google App Engine来提供Go webapp。

I'd like to maximize browser cache longevity, minimize number of requests and still serve the fresh versions of my css/js/png, and I believe revving filenames is a best practice to achieve this. 我想最大限度地提高浏览器缓存的使用寿命,最大限度地减少请求数量,并仍然提供我的css / js / png的新版本,我相信加速文件名是实现这一目标的最佳实践。 Also as adding a variable querystring ( /v1/img/logo.png?2014-01-29 ) might cause proxy and cache problems, I prefer to show a variable directory name ( /v1_2014-01-29/img/logo.png ), pointing to the same underlying server dir. 另外,添加变量查询字符串( /v1/img/logo.png?2014-01-29 )可能会导致代理和缓存问题,我更喜欢显示变量目录名称( /v1_2014-01-29/img/logo.png ),指向相同的底层服务器目录。

Seems to me that whatever part of the URL that is beyond the match of the url definition (which matches from the start) is appended to the static_dir. 在我看来,URL的任何超出url定义匹配的部分(从开头匹配)都附加到static_dir。

So the following handler should match /v1_2014-01-29/img/logo.png if the file path is static/v1/img/logo.png (tried with Python): 因此,如果文件路径为static/v1/img/logo.png (使用Python尝试),则以下处理程序应匹配/v1_2014-01-29/img/logo.png

- url: /v1_(\d+-?)+
  static_dir: static/v1

After olivierdm's answer I changed my yaml into : 在olivierdm的回答之后,我将我的yaml改为:

- url: /v1_.*_
  static_dir: static/v1
  expiration: "364d"

and my html templates to produce /v1_2014-01-29_/img/logo.png . 和我的html模板生成/v1_2014-01-29_/img/logo.png

Basically, the extra arbitrary character underscore _ forces .* to match 2014-01-29 , not the empty string. 基本上,额外的任意字符下划线_.*来匹配2014-01-29 ,而不是空字符串。

Now every time I want the visitors to reload the static files, I just change the date in the tempating (I don't touch the app.yaml anymore). 现在,每当我希望访问者重新加载静态文件时,我只是改变了诱惑中的日期(我不再触摸app.yaml)。 Also, any accidental request to an "outdated" URL will still succeed and serve the fresh resource. 此外,对“过时”URL的任何意外请求仍将成功并提供新资源。

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

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