dongyangben6144 2014-08-25 15:15
浏览 57

使用Google App Engine和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.

  • 写回答

1条回答 默认 最新

  • doutouhe5343 2014-08-28 16:59
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)