Support lading page (#5)

* More specific Route
* Support /editos  /view

* support views

* support lading, sitemap, ouath callback
pull/6/head
Yohany Flores Suarez 5 years ago committed by Quentin McGaw
parent 6eb5f63530
commit a6e6fc7fb3

@ -52,5 +52,6 @@ EXPOSE 8000
HEALTHCHECK --start-period=1s --interval=100s --timeout=2s --retries=1 CMD ["/server","healthcheck"] HEALTHCHECK --start-period=1s --interval=100s --timeout=2s --retries=1 CMD ["/server","healthcheck"]
USER 1000 USER 1000
ENTRYPOINT ["/server"] ENTRYPOINT ["/server"]
COPY --from=stackedit --chown=1000 /stackedit/dist /html COPY --from=stackedit --chown=1000 /stackedit/dist /html/dist
COPY --from=stackedit --chown=1000 /stackedit/static /html/static
COPY --from=server --chown=1000 /tmp/gobuild/app /server COPY --from=server --chown=1000 /tmp/gobuild/app /server

@ -4,3 +4,5 @@ require (
github.com/julienschmidt/httprouter v1.2.0 github.com/julienschmidt/httprouter v1.2.0
github.com/kyokomi/emoji v1.5.1 github.com/kyokomi/emoji v1.5.1
) )
go 1.13

@ -12,7 +12,10 @@ import (
"github.com/kyokomi/emoji" "github.com/kyokomi/emoji"
) )
const defaultListeningPort = "8000" const (
defaultListeningPort = "8000"
defaultConf = `{"dropboxAppKey":"","dropboxAppKeyFull":"","githubClientId":"","googleClientId":"","googleApiKey":"","wordpressClientId":"","allowSponsorship":true}`
)
func parseEnv() (listeningPort string) { func parseEnv() (listeningPort string) {
listeningPort = os.Getenv("LISTENINGPORT") listeningPort = os.Getenv("LISTENINGPORT")
@ -97,15 +100,42 @@ func main() {
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
}) })
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if len(r.URL.Path) >= 4 && r.URL.Path[:4] == "/app" {
if len(r.URL.Path) == 4 { switch {
r.URL.Path = "/" case r.URL.Path == "/conf" || r.URL.Path == "/app/conf":
// TODO: read from `docker config` or ENVIROMENT or File
fmt.Fprintf(w, "%s", defaultConf)
return;
case r.URL.Path == "/":
r.URL.Path = "/static/landing/"
case strings.HasPrefix(r.URL.Path, "/static/landing/"):
r.URL.Path = r.URL.Path
case r.URL.Path == "/sitemap.xml":
r.URL.Path = "/static/sitemap.xml"
case r.URL.Path == "/oauth2/callback":
r.URL.Path = "/static/oauth2/callback.html"
case r.URL.Path == "/app" || r.URL.Path == "/app/":
r.URL.Path = "/dist/"
case strings.HasPrefix(r.URL.Path, "/app/"):
r.URL.Path = "/dist/" + r.URL.Path[4:]
default:
if strings.HasPrefix(r.URL.Path, "/") {
r.URL.Path = "/dist" + r.URL.Path
} else { } else {
r.URL.Path = strings.Replace("/"+r.URL.Path[5:], "//", "/", -1) r.URL.Path = "/dist/" + r.URL.Path
} }
} }
http.ServeFile(w, r, "/html/"+r.URL.Path[1:])
}) http.ServeFile(w, r, "/html" + r.URL.Path)
});
log.Println("Web UI listening on 0.0.0.0:" + listeningPort + emoji.Sprint(" :ear:")) log.Println("Web UI listening on 0.0.0.0:" + listeningPort + emoji.Sprint(" :ear:"))
log.Fatal(http.ListenAndServe("0.0.0.0:"+listeningPort, nil)) log.Fatal(http.ListenAndServe("0.0.0.0:"+listeningPort, nil))
} }

Loading…
Cancel
Save