This is an automated email from the ASF dual-hosted git repository.

linkinstar pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/answer.git


The following commit(s) were added to refs/heads/dev by this push:
     new d468e2ba feat: add env for glob load template files by gin debug render
d468e2ba is described below

commit d468e2ba8dee2577ff0af8e7cbcfb2b111f6abdb
Author: liruohrh <[email protected]>
AuthorDate: Sun Dec 7 00:51:15 2025 +0800

    feat: add env for glob load template files by gin debug render
---
 internal/base/server/http.go | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/internal/base/server/http.go b/internal/base/server/http.go
index 4fbb04cb..512f3da2 100644
--- a/internal/base/server/http.go
+++ b/internal/base/server/http.go
@@ -22,6 +22,7 @@ package server
 import (
        "html/template"
        "io/fs"
+       "os"
 
        brotli "github.com/anargu/gin-brotli"
        "github.com/apache/answer/internal/base/middleware"
@@ -53,9 +54,14 @@ func NewHTTPServer(debug bool,
        r.Use(brotli.Brotli(brotli.DefaultCompression), 
middleware.ExtractAndSetAcceptLanguage, shortIDMiddleware.SetShortIDFlag())
        r.GET("/healthz", func(ctx *gin.Context) { ctx.String(200, "OK") })
 
-       html, _ := fs.Sub(ui.Template, "template")
-       htmlTemplate := 
template.Must(template.New("").Funcs(funcMap).ParseFS(html, "*"))
-       r.SetHTMLTemplate(htmlTemplate)
+       templatePath := os.Getenv("ANSWER_TEMPLATE_PATH")
+       if templatePath != "" {
+               r.LoadHTMLGlob(templatePath)
+       } else {
+               html, _ := fs.Sub(ui.Template, "template")
+               htmlTemplate := 
template.Must(template.New("").Funcs(funcMap).ParseFS(html, "*"))
+               r.SetHTMLTemplate(htmlTemplate)
+       }
        r.Use(middleware.HeadersByRequestURI())
        viewRouter.Register(r, uiConf.BaseURL)
 

Reply via email to