|
|
@ -1,12 +1,12 @@
|
|
|
|
package main
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/julienschmidt/httprouter"
|
|
|
|
|
|
|
|
"github.com/kyokomi/emoji"
|
|
|
|
"github.com/kyokomi/emoji"
|
|
|
|
"github.com/qdm12/golibs/healthcheck"
|
|
|
|
"github.com/qdm12/golibs/healthcheck"
|
|
|
|
"github.com/qdm12/golibs/logging"
|
|
|
|
"github.com/qdm12/golibs/logging"
|
|
|
@ -47,38 +47,30 @@ func main() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
logging.Infof("Using root URL %q", rootURL)
|
|
|
|
logging.Infof("Using root URL %q", rootURL)
|
|
|
|
|
|
|
|
|
|
|
|
handler := func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
productionRouter := http.NewServeMux()
|
|
|
|
path := r.URL.Path
|
|
|
|
productionRouter.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
switch path {
|
|
|
|
urlStackeditPath := strings.TrimPrefix(r.URL.Path, rootURL)
|
|
|
|
case rootURL + "/conf", rootURL + "/app/conf":
|
|
|
|
filepath := "/dist/" + urlStackeditPath
|
|
|
|
// TODO: read from `docker config` or ENVIROMENT or File
|
|
|
|
switch urlStackeditPath {
|
|
|
|
fmt.Fprintf(w, "%s", defaultConf)
|
|
|
|
case "/conf", "/app/conf":
|
|
|
|
|
|
|
|
w.Write(getAllStackeditEnv())
|
|
|
|
return
|
|
|
|
return
|
|
|
|
case rootURL + "/":
|
|
|
|
case "/":
|
|
|
|
path = rootURL + "/static/landing/"
|
|
|
|
filepath = "/static/landing/"
|
|
|
|
case rootURL + "/sitemap.xml":
|
|
|
|
case "/sitemap.xml":
|
|
|
|
path = rootURL + "/static/sitemap.xml"
|
|
|
|
filepath = "/static/sitemap.xml"
|
|
|
|
case rootURL + "/oauth2/callback":
|
|
|
|
case "/oauth2/callback":
|
|
|
|
path = rootURL + "/static/oauth2/callback.html"
|
|
|
|
filepath = "/static/oauth2/callback.html"
|
|
|
|
case rootURL + "/app", rootURL + "/app/":
|
|
|
|
case "/app", "/app/":
|
|
|
|
path = rootURL + "/dist/"
|
|
|
|
filepath = "/dist/"
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
switch {
|
|
|
|
switch {
|
|
|
|
case strings.HasPrefix(path, rootURL+"/app/"):
|
|
|
|
case strings.HasPrefix(urlStackeditPath, "/app/"):
|
|
|
|
path = rootURL + "/dist/" + path[len(rootURL)+4:]
|
|
|
|
filepath = "/dist/" + strings.TrimPrefix(urlStackeditPath, "/app/")
|
|
|
|
case strings.HasPrefix(path, rootURL+"/"):
|
|
|
|
|
|
|
|
path = rootURL + "/dist" + path[len(rootURL):]
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
path = rootURL + "/dist/" + path
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
http.ServeFile(w, r, "/html"+path)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
http.ServeFile(w, r, "/html"+filepath)
|
|
|
|
logging.Info("Web UI listening on 0.0.0.0:" + listeningPort + emoji.Sprint(" :ear:"))
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
productionRouter := httprouter.New()
|
|
|
|
|
|
|
|
productionRouter.HandlerFunc(http.MethodGet, rootURL+"/", handler)
|
|
|
|
|
|
|
|
healthcheckRouter := healthcheck.CreateRouter(func() error { return nil })
|
|
|
|
healthcheckRouter := healthcheck.CreateRouter(func() error { return nil })
|
|
|
|
serverErrs := server.RunServers(
|
|
|
|
serverErrs := server.RunServers(
|
|
|
|
server.Settings{Name: "production", Addr: "0.0.0.0:" + listeningPort, Handler: productionRouter},
|
|
|
|
server.Settings{Name: "production", Addr: "0.0.0.0:" + listeningPort, Handler: productionRouter},
|
|
|
@ -94,3 +86,32 @@ func main() {
|
|
|
|
os.Exit(1)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Returns all stackedit env values as JSON
|
|
|
|
|
|
|
|
func getAllStackeditEnv() []byte {
|
|
|
|
|
|
|
|
env := struct {
|
|
|
|
|
|
|
|
DropboxAppKey string `json:"dropboxAppKey"`
|
|
|
|
|
|
|
|
DropboxAppKeyFull string `json:"dropboxAppKeyFull"`
|
|
|
|
|
|
|
|
GithubClientID string `json:"githubClientId"`
|
|
|
|
|
|
|
|
GithubClientSecret string `json:"githubClientSecret"`
|
|
|
|
|
|
|
|
GoogleClientID string `json:"googleClientId"`
|
|
|
|
|
|
|
|
GoogleAPIKey string `json:"googleApiKey"`
|
|
|
|
|
|
|
|
WordpressClientID string `json:"wordpressClientId"`
|
|
|
|
|
|
|
|
PaypalReceiverEmail string `json:"paypalReceiverEmail"`
|
|
|
|
|
|
|
|
AllowSponsorship bool `json:"allowSponsorship"`
|
|
|
|
|
|
|
|
}{}
|
|
|
|
|
|
|
|
envParams := params.NewEnvParams()
|
|
|
|
|
|
|
|
env.DropboxAppKey, _ = envParams.GetEnv("DROPBOX_APP_KEY")
|
|
|
|
|
|
|
|
env.DropboxAppKeyFull, _ = envParams.GetEnv("DROPBOX_APP_KEY_FULL")
|
|
|
|
|
|
|
|
env.GithubClientID, _ = envParams.GetEnv("GITHUB_CLIENT_ID")
|
|
|
|
|
|
|
|
env.GithubClientSecret, _ = envParams.GetEnv("GITHUB_CLIENT_SECRET")
|
|
|
|
|
|
|
|
env.GoogleClientID, _ = envParams.GetEnv("GOOGLE_CLIENT_ID")
|
|
|
|
|
|
|
|
env.GoogleAPIKey, _ = envParams.GetEnv("GOOGLE_API_KEY")
|
|
|
|
|
|
|
|
env.WordpressClientID, _ = envParams.GetEnv("WORDPRESS_CLIENT_ID")
|
|
|
|
|
|
|
|
env.PaypalReceiverEmail, _ = envParams.GetEnv("PAYPAL_RECEIVER_EMAIL")
|
|
|
|
|
|
|
|
if len(env.PaypalReceiverEmail) > 0 {
|
|
|
|
|
|
|
|
env.AllowSponsorship = true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
b, _ := json.Marshal(env)
|
|
|
|
|
|
|
|
return b
|
|
|
|
|
|
|
|
}
|
|
|
|