summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2022-05-02 16:06:03 +0200
committerLibravatar GitHub <noreply@github.com>2022-05-02 16:06:03 +0200
commit3112949b6e95d9e04355f3912910649ea00ea832 (patch)
tree1698ebe63aeda528c1d522d9b8c424cf11847481
parent[bugfix] Allow self-boosting for any visibility but direct (#510) (diff)
downloadgotosocial-3112949b6e95d9e04355f3912910649ea00ea832.tar.xz
[bugfix] Fix panic when relative tmpl path given to router (#528)
-rw-r--r--internal/router/template.go15
1 files changed, 7 insertions, 8 deletions
diff --git a/internal/router/template.go b/internal/router/template.go
index 7cc9850e0..315f44a56 100644
--- a/internal/router/template.go
+++ b/internal/router/template.go
@@ -34,21 +34,20 @@ import (
// LoadTemplates loads html templates for use by the given engine
func loadTemplates(engine *gin.Engine) error {
templateBaseDir := viper.GetString(config.Keys.WebTemplateBaseDir)
+ if templateBaseDir == "" {
+ return fmt.Errorf("%s cannot be empty and must be a relative or absolute path", config.Keys.WebTemplateBaseDir)
+ }
- if !filepath.IsAbs(templateBaseDir) {
- cwd, err := os.Getwd()
- if err != nil {
- return fmt.Errorf("error getting current working directory: %w", err)
- }
-
- templateBaseDir = filepath.Join(cwd, viper.GetString(config.Keys.WebTemplateBaseDir))
+ templateBaseDir, err := filepath.Abs(templateBaseDir)
+ if err != nil {
+ return fmt.Errorf("error getting absolute path of %s: %s", templateBaseDir, err)
}
if _, err := os.Stat(filepath.Join(templateBaseDir, "index.tmpl")); err != nil {
return fmt.Errorf("%s doesn't seem to contain the templates; index.tmpl is missing: %w", templateBaseDir, err)
}
- engine.LoadHTMLGlob(fmt.Sprintf("%s*", templateBaseDir))
+ engine.LoadHTMLGlob(filepath.Join(templateBaseDir, "*"))
return nil
}