How can I upload a static HTML site on Google App

2019-02-18 04:25发布

Is there any tutorial for this? I have 3 files in my project:

  • index.html
  • index.css
  • index.js

Should be simple, but so far I am lost in huge GAE's documentation.

3条回答
萌系小妹纸
2楼-- · 2019-02-18 04:34

I made a simple Go app that does this very nicely. http://yourdomain.com will serve up index.html and the rest of the pages are accessible at http://yourdomain.com/mypage.html

Here's the yaml:

application: myawesomeapp
version: 1
runtime: go
api_version: go1

handlers:
- url: /.*
  script: _go_app

Here's the go program that will serve up all your static files at the root level:

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)
}

Then throw all your static files in /static directory, run goapp deploy and you're done.

查看更多
beautiful°
3楼-- · 2019-02-18 04:38

You don't need to call out each file individually in app.yaml as Mark suggests; instead, a simple handler like this will suffice:

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

Then put your site in a directory called 'static' under the directory containing app.yaml.

The first handler ensures that index.html is served up any time someone asks for a directory. The second handler serves all other URLs directly from the static dir.

查看更多
该账号已被封号
4楼-- · 2019-02-18 04:38

I don't really think that is what Google intends the service to be used for. But if you really need to serve some static content that is simple.

You define an app.yaml file like so:

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

Then use appcfg update . (assuming your using Linux in the source directory)

查看更多
登录 后发表回答