4

The Google Cloud documentation isn't very precise on the available syntax for the app.yaml file used for my Node.js application.

I used the syntax described in the Python documentation for GAE, from which I've found the handlers mecanism:

    handlers:
    - url: /index.html
      static_files: /public/index.html
      upload: /public/index.html

I've avoid my expressjs rule to serve the /public/index.html content and finally I got a 404 error, meaning GAE is not serving my page as a static content:

    $ curl -i "http://my-project/index.html"
    HTTP/1.1 404 Not Found
    ...

Do you have any clue on this? Node.js is relevant for making APIs, generating dynamic content... But I prefer using the Google backends or even a Nginx server to handle static contents.

Update

Removing the leading slashes didn't fixed the issue. I slightly changed my app.yaml configuration:

    handlers:
    - url: /api/.*
      secure: always
      script: app.js
    - url: /.*
      secure: always
      static_dir: public

And I still get 404 Not found on /index.html, and getting the correct 200 OK answser when calling /api/stuff.

Here is my project tree structure:

    Project root
    |- app.js
    |- app.yaml
    |- package.json
    |- public/
    |  `-- css/
    |     `-- style.css
    |  `-- js/
    |     `-- main.js
    |  `-- index.html
  • Are you still having issues with `static_dir` static file handlers in app.yaml with the Nodejs runtime? Was the answer provided by Dan effective (as it seems unclear from the comments)? – Nicholas Jan 13 '17 at 16:17

1 Answers1

1

The examples at the very documentation page should normally suffice.

You have a leading / in the static_files and upload values, which should be just relative paths to the top of your app dir.

There could be other reasons as well, the starting point would be the logs for your app, either on your development server or on GAE if already deployed.

Update:

According to the Static directory handlers doc:

A static directory example:

handlers:
# All URLs beginning with /stylesheets are treated as paths to static files in
# the stylesheets/ directory.
- url: /stylesheets
  static_dir: stylesheets

url

A URL prefix. This value uses regular expression syntax (and so regexp special characters must be escaped), but it should not contain groupings. All URLs that begin with this prefix are handled by this handler, using the portion of the URL after the prefix as part of the file path.

Based on this quote I'd suspect the wildcards in the url of the app.yaml's handler spec may be causing issues (for example the /index.html might actually be expanded to /index.html/ by the static_dir parsing logic), I'd replace the url to clearly indicate a directory, like this:

- url: /
  secure: always
  static_dir: public

I'm not a fan of tying the top level / of the app's namespace to a static dir, but it may be OK for a generally static app. Make sure you always keep this handler spec last in your app.yaml file to avoid issues.

Dan Cornilescu
  • 37,297
  • 11
  • 54
  • 89
  • Thank you for the answer, I dropped my leading `/`, but nothing changed. I get this error, meaning the handler has been parsed but still the file cannot be found: `Static file referenced by handler not found: public/index.html` – Clément Désiles Oct 23 '15 at 12:40
  • Please edit the question adding the directory structure of your project to show where the `index.html` file resides. – Dan Cornilescu Oct 23 '15 at 16:13
  • I've set up your handler with only one "/", and it's still not working. I still got errors: "Static file referenced by handler not found: public/", "Static file referenced by handler not found: public/index.html", and "Static file referenced by handler not found: public/index.html/" when I request respectively "/", "/index.html", "/index.html/". Do you have any clue? Do you know how to report a bug to the Google developers? Thanks! – Clément Désiles Oct 26 '15 at 09:27
  • You still have the url as `/.*`, not `/`. – Dan Cornilescu Oct 26 '15 at 14:09
  • No its not. I'm using the / in my handlers: - url: / secure: always static_dir: public – Clément Désiles Oct 26 '15 at 15:18
  • My suspicion was confirmed last night, see this Q&A: http://stackoverflow.com/questions/33447890/static-files-are-missing/33448239#33448239 – Dan Cornilescu Oct 31 '15 at 13:00