【问题标题】:Static files not serving when uploaded in Google app engine (SDK Go)在 Google 应用引擎 (SDK Go) 中上传静态文件时不提供服务
【发布时间】:2017-02-02 10:25:28
【问题描述】:

我试图使用谷歌应用引擎云空间。我的程序在 localhost 中运行没有任何问题,但是当我尝试在 google app 引擎中托管它时,不提供静态文件。 app.yaml 如下:

application: myTestApp-nn34322
version: 1
runtime: go
threadsafe: true
api_version: go1

handlers:
- url: /static/css
  static_dir: ../static/css
  mime_type: "text/css"

- url: /static/js
  static_dir: ../static/js
  mime_type: "text/javascript"

- url: /static/images
  static_dir: ../static/images

- url: /.*
  script: _go_app

【问题讨论】:

  • 在尝试获取静态文件时是否收到HTTP 404 错误?另外,app.yamlstatic 文件夹是否在同一个文件夹中?
  • 是的,我收到 404。我正在使用 beegae 框架。所以我的 app.yaml 在主文件夹中。我的静态文件夹与主文件夹一起位于根目录中。
  • 我的感觉是您的static 文件夹没有上传到Appengine。尝试将static 文件夹移动到app.yaml 旁边,当然也可以使用:static_dir: static/xxx
  • @icza 谢谢老兄。有效。如果您将此作为答案发布,那就太好了。

标签: google-app-engine go


【解决方案1】:

您应该将每个静态资源放在您放置 app.yaml 文件的同一文件夹下,否则它们不会上传到 AppEngine。

所以你应该把你的static文件夹放在app.yaml旁边,那么正确的路径当然就是static/xxx,例如:

- url: /static/css
  static_dir: static/css
  mime_type: "text/css"

- url: /static/js
  static_dir: static/js
  mime_type: "text/javascript"

- url: /static/images
  static_dir: static/images

注意:

如果您也打算使用 Go 应用程序中的这些静态文件(例如,您想读取它们的内容),则需要进行特殊处理,因为与静态文件模式匹配的资源在上传后不会被复制到应用程序(静态文件是由不同的服务器提供服务)。详情请见Google App Engine Golang no such file or directory。基本上,您要么必须复制静态文件,要么为静态文件处理程序提供 application_readable 选项。

【讨论】:

    猜你喜欢
    • 2013-11-18
    • 2011-08-07
    • 1970-01-01
    • 1970-01-01
    • 2021-07-30
    • 1970-01-01
    • 1970-01-01
    • 2014-12-20
    • 1970-01-01
    相关资源
    最近更新 更多