2

In my app there is a /static folder which contains all the static resources needed by the app. Here is my handlers for the static resources:

- url: /static
  static_dir: static

This works for files directly in /static, but let's say I also have another folder containing jQuery:

static
  |- jquery
  |   \- jquery.js
  |
  \- images
      \- ...
    

When I try to reach [myapp].appspot.com/static/jquery/jquery.js it would return a 404 and I have no idea why.

Also some of my files including .css and .ttf etc. are giving me a Could not guess mimtype error. I have no idea how to solve that.


Edit

Added my (new) app.yaml. I don't have a dispatch.yaml.

version: 1
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /static/pages_style
  mime_type: text/css
  static_dir: /static/pages_style

- url: /static/images/(.*\.(gif|png|jpg))$
  static_files: static/images/\1
  upload: static/images/.*\.(gif|png|jpg)$

- url: /static/bootstrap 3.3.5
  static_dir: /static/bootstrap 3.3.5

- url: /static/jquery 2.1.4
  static_dir: /static/jquery 2.1.4
    
- url: /.*
  script: myapp.app

libraries:
- name: webapp2
  version: latest
- name: jinja2
  version: latest
Community
  • 1
  • 1
Derek 朕會功夫
  • 92,235
  • 44
  • 185
  • 247
  • for the mimetype error see this Q&A: http://stackoverflow.com/questions/20425364/could-not-guess-mimetype – Dan Cornilescu Oct 31 '15 at 04:12
  • @DanCornilescu Do you know what is causing the 404 problem? – Derek 朕會功夫 Oct 31 '15 at 04:14
  • Unclear yet. The `static_dir` should work recursively as well (assuming the path is correct), something else is going on. Can you pls post your entire content of your `.yaml` module files and that of the `dispatch.yaml` file (if you use one)? – Dan Cornilescu Oct 31 '15 at 04:18
  • @DanCornilescu Added to the question. I don't have a `dispatch.yaml` file. – Derek 朕會功夫 Oct 31 '15 at 04:21
  • Aha. I bet the `/static/(.*\.css)$` `static_files` routing conflicts with the `/static` `static_dir` one. Try to make them non-overlapping, for example change `/static` to be more specific, like `/static/jquery`, move the `.css` files to a `css` subdir side by side with `jquery`, so that you can change `/static/(.*\.css)$` to `/static/css/(.*\.css)$`. You'll need similar stuff to address the mimetype error anyways. – Dan Cornilescu Oct 31 '15 at 04:26
  • @DanCornilescu I've changed all of them (updated above) to be more specific now but it's giving me a 404... One thing I noticed though, is that the images/html always work. Other than those, like .css and .js none of them works. (And now my local server is also serving 404... I don't know what I did wrong) – Derek 朕會功夫 Oct 31 '15 at 04:39
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/93848/discussion-between-dan-cornilescu-and-derek-). – Dan Cornilescu Oct 31 '15 at 04:42

1 Answers1

1

The 404 errors on [myapp].appspot.com/static/jquery/jquery.js requests were caused by a static_files URL pattern being under a static_dir URL path:

- url: /static/(.*\.css)$
  static_files: static/\1
  upload: static/(.*\.css)$

- url: /static
  static_dir: static

In the above example /static/(.*\.css)$ matches are located under /static. I guess the static dir/files routing in the GAE infra gets confused in such cases.

The solution is to make the paths more specific such that the static_dir URLs never include paths matching static_files URL patterns or other static_dir URLs.

About the Could not guess mimetype error, this Q&A explains it well: Could not guess mimetype

Community
  • 1
  • 1
Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97