fixes for SASS generating and endpoints, oauth fix

pull/557/head
hunterlong 2020-05-01 18:49:45 -07:00
parent 4cd669b9d0
commit e7a5b741af
5 changed files with 29 additions and 8 deletions

View File

@ -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

View File

@ -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)

View File

@ -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")

View File

@ -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 {

View File

@ -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