20

我创建了一个 App Engine 应用程序。到目前为止,我只有几个 HTML 文件可供服务。每当有人访问http://example.appengine.com/时,我该怎么做才能让 App Engine 提供 index.html 文件?

目前,我的 app.yaml 文件如下所示:

application: appname
version: 1
runtime: python
api_version: 1

handlers:

- url: /
  static_dir: static_files
4

5 回答 5

40

这应该做你需要的:

https://gist.github.com/873098

说明:在 App Engine Python 中,可以使用正则表达式作为 URL 处理程序,app.yaml并将所有 URL 重定向到静态文件的层次结构。

示例app.yaml

application: your-app-name-here
version: 1
runtime: python
api_version: 1

handlers:
- url: /(.*\.css)
  mime_type: text/css
  static_files: static/\1
  upload: static/(.*\.css)

- url: /(.*\.html)
  mime_type: text/html
  static_files: static/\1
  upload: static/(.*\.html)

- url: /(.*\.js)
  mime_type: text/javascript
  static_files: static/\1
  upload: static/(.*\.js)

- url: /(.*\.txt)
  mime_type: text/plain
  static_files: static/\1
  upload: static/(.*\.txt)

- url: /(.*\.xml)
  mime_type: application/xml
  static_files: static/\1
  upload: static/(.*\.xml)

# image files
- url: /(.*\.(bmp|gif|ico|jpeg|jpg|png))
  static_files: static/\1
  upload: static/(.*\.(bmp|gif|ico|jpeg|jpg|png))

# index files
- url: /(.+)/
  static_files: static/\1/index.html
  upload: static/(.+)/index.html

# redirect to 'url + /index.html' url.
- url: /(.+)
  static_files: static/redirector.html
  upload: static/redirector.html

# site root
- url: /
  static_files: static/index.html
  upload: static/index.html

为了处理对不以可识别类型( , 等)结尾的 URL 的请求,.html或者.png/需要将这些请求重定向到URL + /以便index.html为该目录提供服务。我不知道在 .js 中执行此操作的方法app.yaml,所以我添加了一个 javascript 重定向器。这也可以用一个很小的 ​​python 处理程序来完成。

redirector.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <script language="JavaScript">
      self.location=self.location + "/";
    </script>
  </head>
  <body>
  </body>
</html>
于 2011-04-10T02:47:14.270 回答
9

可以使用 (app.yaml) 来完成:

handlers:
- url: /appurl
  script: myapp.app

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

- url: /
  static_files: staticdir/index.html
  upload: staticdir/index.html
于 2013-11-11T17:44:00.813 回答
9

如果您尝试映射/index.html

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

url:匹配路径并支持正则表达式。

- url: /images
  static_dir: static_files/images

因此,如果您的图像文件在static_files/images/picture.jpg使用时存储:

<img src="/images/picture.jpg" />
于 2011-04-10T01:36:22.960 回答
1

在 WEB-INF/web.xml 中输入:

  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>
于 2011-04-10T00:57:29.870 回答
1

这是我如何让 Jekyll 生成的网站正常工作的 app.yaml:

runtime: python27
api_version: 1
threadsafe: true


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

- url: /assets
  static_dir: _site/assets



  # index files
- url: /(.+)/
  static_files: _site/\1/index.html
  upload: _site/(.+)/index.html

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

- url: /.*
  static_dir: _site
于 2018-05-08T19:21:30.003 回答