user3739818
user3739818

Reputation: 249

Google App Engine app.yaml configuration for /user/.* regex

I'm trying to make a login and profile page. Here is the app.yaml file which works fine for '/' and '/(anything)'. Instead of '/(anything)' I would like to have the path as '/user/.*'. I tried a lot but it only renders the html part of the page. How do I configure my app.yaml, so that it renders with complete CSS and JS and works for '/(anything)/(anything)'?

application: My-App-name
version: 1
runtime: python27
api_version: 1
threadsafe: yes


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)

 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


# site root

- url: /.*
  script: main.app

#- url: /user/.*
#  script: main.app

libraries:
- name: jinja2
  version: latest

PS: I have my folder tree as,

app.yaml

static->CSS,JS,Images,html files

index.yaml main.app

Upvotes: 4

Views: 1633

Answers (1)

GAEfan
GAEfan

Reputation: 11370

Try something like:

- url: /(.+)/(.*\.js)
  mime_type: text/javascript
  static_files: static/\2
  upload: static/(.*\.js)

This will match /anything/file.js as well as /anything/anything/file.js, as well as /junk/static/hellothere/this/matches/everything/file.js, because (.+) also matches all the slashes. If you don't want it to match both, then you need to handle the slashes in the regex (separate handling for characters and slashes):

- url: /([A-Za-z0-9-_]+)/([A-Za-z0-9-_]+)/(.*\.js)
  mime_type: text/javascript
  static_files: static/\3
  upload: static/(.*\.js)

This matches /any-thing/any_th-ing/file.js. If you want to get more specific, you can use:

- url: /user/([A-Za-z0-9-_]+)/(.*\.js)
  mime_type: text/javascript
  static_files: static/\2
  upload: static/(.*\.js)

to match `/user/anything/file.js', or:

- url: /([A-Za-z0-9-_]+)/static/(.*\.js)
  mime_type: text/javascript
  static_files: static/\2
  upload: static/(.*\.js)

to match /anything/static/file.js

Upvotes: 2

Related Questions