gpt4 book ai didi

google-app-engine - 使用 App Engine 提供静态文件

转载 作者:太空宇宙 更新时间:2023-11-03 15:17:59 25 4
gpt4 key购买 nike

我创建了一个 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

最佳答案

这应该可以满足您的需要:

https://gist.github.com/873098

说明:在 App Engine Python 中,可以在 app.yaml 中使用正则表达式作为 URL 处理程序并将所有 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

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

redirector.html :

<!DOCTYPE html>
<html lang="en">
<head>
<script language="JavaScript">
self.location=self.location + "/";
</script>
</head>
<body>
</body>
</html>

关于google-app-engine - 使用 App Engine 提供静态文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5609000/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com