From 4f8a0f873919ad8605d60677376c5eeabd1c0d15 Mon Sep 17 00:00:00 2001 From: konrad Date: Fri, 2 Nov 2018 10:01:28 +0000 Subject: [PATCH] Fixed no root path for templates and static assets (#12) --- Dockerfile | 2 ++ docs/config.md | 2 ++ pkg/config/config.go | 8 ++++++++ pkg/mail/send_mail.go | 2 +- pkg/routes/routes.go | 2 +- 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index b8a1c81c8..0ade95158 100644 --- a/Dockerfile +++ b/Dockerfile @@ -40,5 +40,7 @@ COPY --from=build-env /go/src/code.vikunja.io/api/public /app/vikunja/public COPY --from=build-env /go/src/code.vikunja.io/api/templates /app/vikunja/templates COPY --from=build-env /go/src/code.vikunja.io/api/vikunja /app/vikunja/vikunja +ENV VIKUNJA_SERVICE_ROOTPATH=/app/vikunja/ + ENTRYPOINT ["/bin/s6-svscan", "/etc/services.d"] CMD [] diff --git a/docs/config.md b/docs/config.md index 10ea6f915..1e63c9c74 100644 --- a/docs/config.md +++ b/docs/config.md @@ -31,6 +31,8 @@ service: interface: ":3456" # The URL of the frontend, used to send password reset emails. frontendurl: "" + # The base path on the file system where the binary and assets are + rootpath: database: # Database type to use. Supported types are mysql and sqlite. diff --git a/pkg/config/config.go b/pkg/config/config.go index bd3162b7b..7504879be 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -4,6 +4,8 @@ import ( "crypto/rand" "fmt" "github.com/spf13/viper" + "os" + "path/filepath" "strings" ) @@ -21,6 +23,12 @@ func InitConfig() (err error) { viper.SetDefault("service.JWTSecret", random) viper.SetDefault("service.interface", ":3456") viper.SetDefault("service.frontendurl", "") + ex, err := os.Executable() + if err != nil { + panic(err) + } + exPath := filepath.Dir(ex) + viper.SetDefault("service.rootpath", exPath) // Database viper.SetDefault("database.type", "sqlite") viper.SetDefault("database.host", "localhost") diff --git a/pkg/mail/send_mail.go b/pkg/mail/send_mail.go index 4c467d12d..3ba19a0a3 100644 --- a/pkg/mail/send_mail.go +++ b/pkg/mail/send_mail.go @@ -69,7 +69,7 @@ func SendMailWithTemplate(to, subject, tpl string, data map[string]interface{}) var plainContent bytes.Buffer t := &Template{ - Templates: template.Must(template.ParseGlob("templates/mail/*.tmpl")), + Templates: template.Must(template.ParseGlob(viper.GetString("service.rootpath") + "/templates/mail/*.tmpl")), } boundary := "np" + utils.MakeRandomString(13) diff --git a/pkg/routes/routes.go b/pkg/routes/routes.go index 27e3e46bf..54affded8 100644 --- a/pkg/routes/routes.go +++ b/pkg/routes/routes.go @@ -61,7 +61,7 @@ func RegisterRoutes(e *echo.Echo) { a := e.Group("/api/v1") // Swagger UI - a.Static("/swagger", "public/swagger") + a.Static("/swagger", viper.GetString("service.rootpath")+"/public/swagger") a.POST("/login", apiv1.Login) a.POST("/register", apiv1.RegisterUser)