public
Last active

GAE: App.yaml designed for serving a static site on Google App Engine (Python). Copy your static html and files into a folder called "static" next to app.yaml. Contains a bunch of mimetype declarations from html5boilerplate's .htaccess. May not be neces

  • Download Gist
app.yaml
YAML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
application: you-app-name-here
version: 1
runtime: python
api_version: 1
 
default_expiration: "30d"
 
handlers:
- url: /(.*\.(appcache|manifest))
mime_type: text/cache-manifest
static_files: static/\1
upload: static/(.*\.(appcache|manifest))
expiration: "0m"
 
- url: /(.*\.atom)
mime_type: application/atom+xml
static_files: static/\1
upload: static/(.*\.atom)
expiration: "1h"
 
- url: /(.*\.crx)
mime_type: application/x-chrome-extension
static_files: static/\1
upload: static/(.*\.crx)
 
- url: /(.*\.css)
mime_type: text/css
static_files: static/\1
upload: static/(.*\.css)
 
- url: /(.*\.eot)
mime_type: application/vnd.ms-fontobject
static_files: static/\1
upload: static/(.*\.eot)
 
- url: /(.*\.htc)
mime_type: text/x-component
static_files: static/\1
upload: static/(.*\.htc)
 
- url: /(.*\.html)
mime_type: text/html
static_files: static/\1
upload: static/(.*\.html)
expiration: "1h"
 
- url: /(.*\.ico)
mime_type: image/x-icon
static_files: static/\1
upload: static/(.*\.ico)
expiration: "7d"
 
- url: /(.*\.js)
mime_type: text/javascript
static_files: static/\1
upload: static/(.*\.js)
 
- url: /(.*\.json)
mime_type: application/json
static_files: static/\1
upload: static/(.*\.json)
expiration: "1h"
 
- url: /(.*\.m4v)
mime_type: video/m4v
static_files: static/\1
upload: static/(.*\.m4v)
 
- url: /(.*\.mp4)
mime_type: video/mp4
static_files: static/\1
upload: static/(.*\.mp4)
 
- url: /(.*\.(ogg|oga))
mime_type: audio/ogg
static_files: static/\1
upload: static/(.*\.(ogg|oga))
 
- url: /(.*\.ogv)
mime_type: video/ogg
static_files: static/\1
upload: static/(.*\.ogv)
 
- url: /(.*\.otf)
mime_type: font/opentype
static_files: static/\1
upload: static/(.*\.otf)
 
- url: /(.*\.rss)
mime_type: application/rss+xml
static_files: static/\1
upload: static/(.*\.rss)
expiration: "1h"
 
- url: /(.*\.safariextz)
mime_type: application/octet-stream
static_files: static/\1
upload: static/(.*\.safariextz)
 
- url: /(.*\.(svg|svgz))
mime_type: images/svg+xml
static_files: static/\1
upload: static/(.*\.(svg|svgz))
 
- url: /(.*\.swf)
mime_type: application/x-shockwave-flash
static_files: static/\1
upload: static/(.*\.swf)
 
- url: /(.*\.ttf)
mime_type: font/truetype
static_files: static/\1
upload: static/(.*\.ttf)
 
- url: /(.*\.txt)
mime_type: text/plain
static_files: static/\1
upload: static/(.*\.txt)
 
- url: /(.*\.unity3d)
mime_type: application/vnd.unity
static_files: static/\1
upload: static/(.*\.unity3d)
 
- url: /(.*\.webm)
mime_type: video/webm
static_files: static/\1
upload: static/(.*\.webm)
 
- url: /(.*\.webp)
mime_type: image/webp
static_files: static/\1
upload: static/(.*\.webp)
 
- url: /(.*\.woff)
mime_type: application/x-font-woff
static_files: static/\1
upload: static/(.*\.woff)
 
- url: /(.*\.xml)
mime_type: application/xml
static_files: static/\1
upload: static/(.*\.xml)
expiration: "1h"
 
- url: /(.*\.xpi)
mime_type: application/x-xpinstall
static_files: static/\1
upload: static/(.*\.xpi)
 
# image files
- url: /(.*\.(bmp|gif|ico|jpeg|jpg|png))
static_files: static/\1
upload: static/(.*\.(bmp|gif|ico|jpeg|jpg|png))
 
# audio files
- url: /(.*\.(mid|midi|mp3|wav))
static_files: static/\1
upload: static/(.*\.(mid|midi|mp3|wav))
 
# windows files
- url: /(.*\.(doc|exe|ppt|rtf|xls))
static_files: static/\1
upload: static/(.*\.(doc|exe|ppt|rtf|xls))
 
# compressed files
- url: /(.*\.(bz2|gz|rar|tar|tgz|zip))
static_files: static/\1
upload: static/(.*\.(bz2|gz|rar|tar|tgz|zip))
 
# index files
- url: /(.+)/
static_files: static/\1/index.html
upload: static/(.+)/index.html
expiration: "15m"
 
- url: /(.+)
static_files: static/\1/index.html
upload: static/(.+)/index.html
expiration: "15m"
 
# site root
- url: /
static_files: static/index.html
upload: static/index.html
expiration: "15m"
readme.markdown
Markdown

App.yaml designed for serving a static site on Google App Engine (Python). Copy your static html and files into a folder called "static" next to app.yaml. Contains a bunch of mimetype declarations from html5boilerplate's .htaccess. May not be necessary for most situations.

my_site
  app.yaml
  static
    index.html
    ...

The static folder is invisible when serving (i.e. my_site/static/index.html is accessed as http://your-app-name-here.appspot.com/index.html.

Remember: No spaces in file or path names. Case sensitive.

Thanks.
however mypp.appspot.com/about gives an error.
i have to include the trailing slash
mypp.appspot.com/about/

Is there any way to fix this?

Hi bbalegere,

you need to place ? mark after last slash, it makes it optional:

# index files
- url: /(.*)/?
  static_files: static/\1/index.html
  upload: static/(.*)/index.html
  expiration: "15m"

@altitudebreath - Nice one character fix. Thanks.

There is another problem.
mypp.appspot.com/about this works fine.
but mypp.appspot.com/about/ this does not.Any way to make both kinds of urls to work properly?
The url should open properly with or without trailing slash.

okay, should work both ways now.

Its working both ways now.But there is a problem when you click on a link in a page opened without the trailing slash.

If you open mypp.appspot.com/about and that page has link to a sub page,then it does not open.
The html code in the about page is like this

<a href="subpage/">subpage</a>

When a user clicks on it, mypp.appspot.com/subpage/ is opened instead of mypp.appspot.com/about/subpage/ .

However when the about page is accessed with the trailing slash , mypp.appspot.com/about/ , then mypp.appspot.com/about/subpage/ opens correctly when the link is clicked.

Thanks for this. You just saved me a lot of trouble.

You might want to add:

- url: /(.*\.pdf)
  mime_type: application/pdf
  static_files: static/\1
  upload: static/(.*\.pdf)

tnx buddy
but would you tell me how to ulpoad php files????

GAE doesn't host PHP.

is there any way to convert php in js?

The yaml works perfectly. However, I would like to create a url handler for my scripts. For eg. is it possible to map /app to my script main.py?

If you put your "/app" handler before the wildcard handlers "/(.+)/" (around line 170), it should work.

For some reason images don't seem to load anymore, although they did with:

application: myApp
version: 1
runtime: python
api_version: 1

handlers:
# Accessing URL '/' on the site should show the public/index.html file
- url: /
  static_files: public/index.html
  upload: public/index.html

# Accessing anything under '/' (i.e. any URL at all) should return that page from folder public 
- url: /
  static_dir: public```

Is there a way to display 404 pages?

For ttf I think it's better to use the application/x-font-ttf instead of font/truetype

https://github.com/h5bp/html5-boilerplate/blob/master/.htaccess#L148

Thanks a lot !!!!!!! very helpful !!!!!

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.