Druxtan
Druxtan

Reputation: 1329

Static file with Google App Engine and Go

I have a problem.

I can't to access to any file from my static dir.

app.yaml:

application: campana-web-1
version: 1
runtime: go
api_version: go1

handlers:
- url: /hello
  script: _go_app
- url: /.*
  static_dir: web

Structure:

campana-web-1:
  +-- src:
      +-- hello.go
  +-- web:
      +-- index.html
      +-- test.jpg
  +-- app.yaml

I use goapp deploy .

When I go to http://website.com/hello it work, but not when I replace hello by test.jpg or index.html I have

Error: Not Found

The requested URL / was not found on this server.

I miss something?

Thank you.

Upvotes: 1

Views: 297

Answers (1)

dyoo
dyoo

Reputation: 12003

The static_dir feature maps directories to directories, but not files to directories as you're trying to do.

If you want to map a collection of files with globs (and no containing directory), then use a combination of static_files and upload instead.

For your case, it'd be:

- url: /(.*)
  static_files: web/\1
  upload: web/.*

But you can use static_dir, just don't use the glob part:

- url: /
  static_dir: web

This, too, should do the trick.

See the Static Directory Handlers and Static File Patterns sections in the documentation again, and in particular, the section about static_dir that says: "Everything after the end of the matched url pattern is appended to static_dir to form the full path to the requested file." That's why what you're doing doesn't work: the static_dir feature is much more limited in scope than what you're thinking.

Upvotes: 1

Related Questions