How can I upload a static HTML site on Google App Engine?

后端 未结 3 883
执念已碎
执念已碎 2021-01-14 00:53

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

3条回答
  •  南方客
    南方客 (楼主)
    2021-01-14 01:31

    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.

提交回复
热议问题