From a6e6fc7fb3ed55caeb7489b264cef4bd7cce7004 Mon Sep 17 00:00:00 2001 From: Yohany Flores Suarez Date: Fri, 10 Jan 2020 14:42:56 -0500 Subject: [PATCH] Support lading page (#5) * More specific Route * Support /editos /view * support views * support lading, sitemap, ouath callback --- Dockerfile | 3 ++- go.mod | 2 ++ main.go | 44 +++++++++++++++++++++++++++++++++++++------- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index b8cee92..c70aa04 100644 --- a/Dockerfile +++ b/Dockerfile @@ -52,5 +52,6 @@ EXPOSE 8000 HEALTHCHECK --start-period=1s --interval=100s --timeout=2s --retries=1 CMD ["/server","healthcheck"] USER 1000 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 diff --git a/go.mod b/go.mod index f9bcebb..43ddaf0 100644 --- a/go.mod +++ b/go.mod @@ -4,3 +4,5 @@ require ( github.com/julienschmidt/httprouter v1.2.0 github.com/kyokomi/emoji v1.5.1 ) + +go 1.13 diff --git a/main.go b/main.go index 20c8735..9bcedce 100644 --- a/main.go +++ b/main.go @@ -12,7 +12,10 @@ import ( "github.com/kyokomi/emoji" ) -const defaultListeningPort = "8000" +const ( + defaultListeningPort = "8000" + defaultConf = `{"dropboxAppKey":"","dropboxAppKeyFull":"","githubClientId":"","googleClientId":"","googleApiKey":"","wordpressClientId":"","allowSponsorship":true}` +) func parseEnv() (listeningPort string) { listeningPort = os.Getenv("LISTENINGPORT") @@ -97,15 +100,42 @@ func main() { w.WriteHeader(http.StatusOK) }) 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 { - r.URL.Path = "/" + + switch { + 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 { - 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.Fatal(http.ListenAndServe("0.0.0.0:"+listeningPort, nil)) }