google-app-engine – 使用App Engine提供靜態檔案
,我可以做什麼來讓App Engine提供index.html檔案?
目前,我的app.yaml檔案如下所示:
application: appname version: 1 runtime: python api_version: 1 handlers: - url: / static_dir: static_files
這應該做你所需要的:
https://gist.github.com/873098
說明:在App Engine Python中,可以使用正則表示式作為app.yaml中的URL處理程式,並將所有URL重定向到靜態檔案的層次結構.
示例app.yaml:
application: your-app-name-here version: 1 runtime: python api_version: 1 handlers: - url: /(.*\.css) mime_type: text/css static_files: static/\1 upload: static/(.*\.css) - url: /(.*\.html) mime_type: text/html static_files: static/\1 upload: static/(.*\.html) - url: /(.*\.js) mime_type: text/javascript static_files: static/\1 upload: static/(.*\.js) - url: /(.*\.txt) mime_type: text/plain static_files: static/\1 upload: static/(.*\.txt) - url: /(.*\.xml) mime_type: application/xml static_files: static/\1 upload: static/(.*\.xml) # image files - url: /(.*\.(bmp|gif|ico|jpeg|jpg|png)) static_files: static/\1 upload: static/(.*\.(bmp|gif|ico|jpeg|jpg|png)) # index files - url: /(.+)/ static_files: static/\1/index.html upload: static/(.+)/index.html # redirect to 'url + /index.html' url. - url: /(.+) static_files: static/redirector.html upload: static/redirector.html # site root - url: / static_files: static/index.html upload: static/index.html
為了處理不以識別型別(.html,.png等)結尾的網址的請求或/您需要將這些請求重定向到URL /,因此該目錄的index.html已被提供.我不知道在app.yaml中有什麼辦法,所以我添加了一個javascript重定向器.這也可以用一個很小的python處理程式來完成.
redirector.html:
<!DOCTYPE html> <html lang="en"> <head> <script language="JavaScript"> self.location=self.location + "/"; </script> </head> <body> </body> </html>
http://stackoverflow.com/questions/5609000/serve-static-file-using-app-engine