Google app engine 如何在Google App Engine上上传静态HTML站点?
有这方面的教程吗? 我的项目中有3个文件:Google app engine 如何在Google App Engine上上传静态HTML站点?,google-app-engine,Google App Engine,有这方面的教程吗? 我的项目中有3个文件: index.html index.css index.js 应该很简单,但到目前为止,我对GAE的大量文档感到迷茫。我真的不认为这是谷歌打算使用该服务的目的。但是如果你真的需要提供一些简单的静态内容 您可以这样定义一个文件: application: staticapp version: 1 runtime: python27 api_version: 1 threadsafe: true handlers: - url: / static_
- index.html
- index.css
- index.js
应该很简单,但到目前为止,我对GAE的大量文档感到迷茫。我真的不认为这是谷歌打算使用该服务的目的。但是如果你真的需要提供一些简单的静态内容 您可以这样定义一个文件:
application: staticapp
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /
static_files: index.html
upload: index.html
- url: /index.css
static_files: index.css
upload: index.css
-url: /index.js
static_files: index.js
upload: index.js
然后使用
appcfg update.
(假设您在源目录中使用Linux)您不需要像Mark建议的那样在app.yaml中单独调用每个文件;相反,这样一个简单的处理程序就足够了:
application: myapp
version: main
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /(.*)/
static_files: \1/index.html
upload: .*/index.html
- url: /.*
static_dir: static
然后将您的站点放在包含app.yaml
的目录下名为“static”的目录中
第一个处理程序确保在任何时候有人请求目录时提供
index.html
。第二个处理程序直接从静态目录提供所有其他URL。我制作了一个简单的Go应用程序,可以很好地实现这一点。将提供index.html,其余页面可在
以下是yaml:
application: myawesomeapp
version: 1
runtime: go
api_version: go1
handlers:
- url: /.*
script: _go_app
下面是一个go程序,它将在根级别提供所有静态文件:
package hello
import (
"net/http"
)
func init() {
http.HandleFunc("/", handler)
}
func handler(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "static/"+r.URL.Path)
}
然后将所有静态文件放入/static目录,运行goapp deploy,就完成了 谢谢。我正在使用windows GAE启动器。但是,我现在在部署时遇到此错误:AppInfoExternal类型的对象的意外属性'-url'。您必须等待Windows用户提供帮助。这在Linux上有效,注意我更新了答案,因为我需要添加threadsafe和api_版本。我试过使用Windows Launcher一次,但无法让它工作,因为它在Linux上非常简单*nix确实是进行web开发的最佳场所。如果应用程序需要图像,您还需要添加一行来提供图像。让我知道我可以添加它。@Ognjen我刚刚注意到你的错误。你有
-url
你应该有-url
注意这里的空白。尼克,你在改进我的代码时,介意看看这个吗?;-)