load html file as template for production

This commit is contained in:
Alireza Ahmadi
2024-02-27 23:11:55 +01:00
parent 541e54c9a4
commit 037dbbd7a0
+9 -3
View File
@@ -4,6 +4,7 @@ import (
"context" "context"
"crypto/tls" "crypto/tls"
"embed" "embed"
"html/template"
"io" "io"
"io/fs" "io/fs"
"net" "net"
@@ -53,6 +54,14 @@ func (s *Server) initRouter() (*gin.Engine, error) {
engine := gin.Default() engine := gin.Default()
// Load the HTML template
t := template.New("").Funcs(engine.FuncMap)
template, err := t.ParseFS(content, "html/index.html")
if err != nil {
return nil, err
}
engine.SetHTMLTemplate(template)
base_url, err := s.settingService.GetWebPath() base_url, err := s.settingService.GetWebPath()
if err != nil { if err != nil {
return nil, err return nil, err
@@ -96,9 +105,6 @@ func (s *Server) initRouter() (*gin.Engine, error) {
group_api := engine.Group(base_url + "api") group_api := engine.Group(base_url + "api")
api.NewAPIHandler(group_api) api.NewAPIHandler(group_api)
// Load the HTML template
engine.LoadHTMLFiles("backend/web/html/index.html")
// Serve index.html as the entry point // Serve index.html as the entry point
// Handle all other routes by serving index.html // Handle all other routes by serving index.html
engine.NoRoute(func(c *gin.Context) { engine.NoRoute(func(c *gin.Context) {