load html file as template for production
This commit is contained in:
+9
-3
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user