Fixed no root path for templates and static assets (#12)

This commit is contained in:
konrad 2018-11-02 10:01:28 +00:00 committed by Gitea
parent c51ca4dd26
commit 4f8a0f8739
5 changed files with 14 additions and 2 deletions

View file

@ -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/templates /app/vikunja/templates
COPY --from=build-env /go/src/code.vikunja.io/api/vikunja /app/vikunja/vikunja 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"] ENTRYPOINT ["/bin/s6-svscan", "/etc/services.d"]
CMD [] CMD []

View file

@ -31,6 +31,8 @@ service:
interface: ":3456" interface: ":3456"
# The URL of the frontend, used to send password reset emails. # The URL of the frontend, used to send password reset emails.
frontendurl: "" frontendurl: ""
# The base path on the file system where the binary and assets are
rootpath: <the path of the executable>
database: database:
# Database type to use. Supported types are mysql and sqlite. # Database type to use. Supported types are mysql and sqlite.

View file

@ -4,6 +4,8 @@ import (
"crypto/rand" "crypto/rand"
"fmt" "fmt"
"github.com/spf13/viper" "github.com/spf13/viper"
"os"
"path/filepath"
"strings" "strings"
) )
@ -21,6 +23,12 @@ func InitConfig() (err error) {
viper.SetDefault("service.JWTSecret", random) viper.SetDefault("service.JWTSecret", random)
viper.SetDefault("service.interface", ":3456") viper.SetDefault("service.interface", ":3456")
viper.SetDefault("service.frontendurl", "") viper.SetDefault("service.frontendurl", "")
ex, err := os.Executable()
if err != nil {
panic(err)
}
exPath := filepath.Dir(ex)
viper.SetDefault("service.rootpath", exPath)
// Database // Database
viper.SetDefault("database.type", "sqlite") viper.SetDefault("database.type", "sqlite")
viper.SetDefault("database.host", "localhost") viper.SetDefault("database.host", "localhost")

View file

@ -69,7 +69,7 @@ func SendMailWithTemplate(to, subject, tpl string, data map[string]interface{})
var plainContent bytes.Buffer var plainContent bytes.Buffer
t := &Template{ 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) boundary := "np" + utils.MakeRandomString(13)

View file

@ -61,7 +61,7 @@ func RegisterRoutes(e *echo.Echo) {
a := e.Group("/api/v1") a := e.Group("/api/v1")
// Swagger UI // Swagger UI
a.Static("/swagger", "public/swagger") a.Static("/swagger", viper.GetString("service.rootpath")+"/public/swagger")
a.POST("/login", apiv1.Login) a.POST("/login", apiv1.Login)
a.POST("/register", apiv1.RegisterUser) a.POST("/register", apiv1.RegisterUser)