diff --git a/Dockerfile b/Dockerfile index 585592a6..be485d89 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,6 +11,7 @@ COPY --from=base /usr/local/share/ca-certificates /usr/local/share/ WORKDIR /app ENV IS_DOCKER=true +ENV SASS=/usr/local/bin/sass ENV STATPING_DIR=/app ENV PORT=8080 diff --git a/handlers/dashboard.go b/handlers/dashboard.go index 93d93193..5a59b53a 100644 --- a/handlers/dashboard.go +++ b/handlers/dashboard.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/dgrijalva/jwt-go" "github.com/statping/statping/source" + "github.com/statping/statping/types/errors" "github.com/statping/statping/types/users" "github.com/statping/statping/utils" "net/http" @@ -36,7 +37,7 @@ type themeApi struct { Mobile string `json:"mobile"` } -func apiThemeHandler(w http.ResponseWriter, r *http.Request) { +func apiThemeViewHandler(w http.ResponseWriter, r *http.Request) { var base, variables, mobile, dir string assets := utils.Directory + "/assets" @@ -93,6 +94,12 @@ func apiThemeSaveHandler(w http.ResponseWriter, r *http.Request) { func apiThemeCreateHandler(w http.ResponseWriter, r *http.Request) { dir := utils.Params.GetString("STATPING_DIR") + if source.UsingAssets(dir) { + err := errors.New("assets have already been created") + log.Errorln(err) + sendErrorJson(err, w, r) + return + } utils.Log.Infof("creating assets in folder: %s/%s", dir, "assets") if err := source.CreateAllAssets(dir); err != nil { log.Errorln(err) diff --git a/handlers/routes.go b/handlers/routes.go index 5a7c5d12..291a584d 100644 --- a/handlers/routes.go +++ b/handlers/routes.go @@ -80,12 +80,12 @@ func Router() *mux.Router { api.Handle("/api/clear_cache", authenticated(apiClearCacheHandler, false)) api.Handle("/api/core", authenticated(apiCoreHandler, false)).Methods("POST") api.Handle("/api/oauth", scoped(apiOAuthHandler)).Methods("GET") - api.Handle("/api/oauth/{provider}", http.HandlerFunc(oauthHandler)) + api.Handle("/oauth/{provider}", http.HandlerFunc(oauthHandler)) api.Handle("/api/logs", authenticated(logsHandler, false)).Methods("GET") api.Handle("/api/logs/last", authenticated(logsLineHandler, false)).Methods("GET") // API SCSS and ASSETS Routes - api.Handle("/api/theme", authenticated(apiThemeHandler, false)).Methods("GET") + api.Handle("/api/theme", authenticated(apiThemeViewHandler, false)).Methods("GET") api.Handle("/api/theme", authenticated(apiThemeSaveHandler, false)).Methods("POST") api.Handle("/api/theme/create", authenticated(apiThemeCreateHandler, false)).Methods("GET") api.Handle("/api/theme", authenticated(apiThemeRemoveHandler, false)).Methods("DELETE") diff --git a/source/source.go b/source/source.go index 0da3e723..4db7ce13 100644 --- a/source/source.go +++ b/source/source.go @@ -45,8 +45,13 @@ func scssRendered(name string) string { func CompileSASS(files ...string) error { sassBin, err := exec.LookPath("sass") if err != nil { + log.Warnf("could not find sass executable in PATH: ", err) return err } + sassEnv := utils.Params.GetString("SASS") + if sassEnv != "" { + sassBin = sassEnv + } for _, file := range files { scssFile := fmt.Sprintf("%v/assets/%v", utils.Params.GetString("STATPING_DIR"), file) @@ -125,10 +130,18 @@ func CreateAllAssets(folder string) error { log.Infoln(fmt.Sprintf("Dump Statping assets into %v/assets", folder)) fp := filepath.Join - MakePublicFolder(fp(folder, "/assets")) - MakePublicFolder(fp(folder, "assets", "js")) - MakePublicFolder(fp(folder, "assets", "css")) - MakePublicFolder(fp(folder, "assets", "scss")) + if err := MakePublicFolder(fp(folder, "/assets")); err != nil { + return err + } + if err := MakePublicFolder(fp(folder, "assets", "js")); err != nil { + return err + } + if err := MakePublicFolder(fp(folder, "assets", "css")); err != nil { + return err + } + if err := MakePublicFolder(fp(folder, "assets", "scss")); err != nil { + return err + } log.Infoln("Inserting scss, css, and javascript files into assets folder") if err := CopyAllToPublic(TmplBox); err != nil { diff --git a/utils/utils.go b/utils/utils.go index db01aac2..2085b8f2 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -118,7 +118,7 @@ func (t Timestamp) Ago() string { // Command will run a terminal command with 'sh -c COMMAND' and return stdout and errOut as strings // in, out, err := Command("sass assets/scss assets/css/base.css") func Command(name string, args ...string) (string, string, error) { - Log.Info("running command: " + name + strings.Join(args, " ")) + Log.Info("Running command: " + name + " " + strings.Join(args, " ")) testCmd := exec.Command(name, args...) var stdout, stderr []byte var errStdout, errStderr error