support loading custom frontend templates from file
This commit is contained in:
parent
e62dbbda94
commit
9bd048b646
|
@ -2,5 +2,6 @@
|
|||
/docker/docker-compose.*.yml
|
||||
/ddns
|
||||
dump.rdb
|
||||
index.html
|
||||
/docker/.caddy_mount/
|
||||
/docker/.redis_mount/
|
||||
|
|
|
@ -41,7 +41,7 @@ func (f *Frontend) Run() error {
|
|||
r.Use(gin.Logger())
|
||||
}
|
||||
|
||||
r.SetHTMLTemplate(buildTemplate())
|
||||
r.SetHTMLTemplate(buildTemplate(f.config.CustomTemplatePath))
|
||||
|
||||
r.GET("/", func(g *gin.Context) {
|
||||
g.HTML(200, "index.html", gin.H{"domain": f.config.Domain})
|
||||
|
@ -153,10 +153,18 @@ func extractRemoteAddr(req *http.Request) (string, error) {
|
|||
}
|
||||
|
||||
// Get index template from bindata
|
||||
func buildTemplate() *template.Template {
|
||||
html, err := template.New("index.html").Parse(indexTemplate)
|
||||
func buildTemplate(customTemplatePath string) *template.Template {
|
||||
var html *template.Template
|
||||
var err error
|
||||
|
||||
if customTemplatePath != "" {
|
||||
html, err = template.ParseFiles(customTemplatePath)
|
||||
} else {
|
||||
html, err = template.New("index.html").Parse(indexTemplate)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Fatalf("Error parsing frontend template: %v", err)
|
||||
}
|
||||
|
||||
return html
|
||||
|
|
|
@ -15,6 +15,7 @@ type Config struct {
|
|||
ListenFrontend string
|
||||
ListenBackend string
|
||||
RedisHost string
|
||||
CustomTemplatePath string
|
||||
|
||||
fs *flag.FlagSet
|
||||
}
|
||||
|
@ -33,6 +34,9 @@ func (c *Config) Initialize() {
|
|||
fs.StringVar(&c.ListenFrontend, "listen-frontend", ":8080",
|
||||
"Which socket should the frontend web service use to bind itself")
|
||||
|
||||
fs.StringVar(&c.CustomTemplatePath, "custom-template-path", "",
|
||||
"A path to a custom `index.html` file that will be used instead of the default frontend template")
|
||||
|
||||
fs.StringVar(&c.RedisHost, "redis-host", ":6379",
|
||||
"The Redis socket that should be used")
|
||||
|
||||
|
@ -46,7 +50,9 @@ func (c *Config) Initialize() {
|
|||
}
|
||||
|
||||
func (c *Config) Validate() {
|
||||
c.fs.Parse(os.Args[1:])
|
||||
if err := c.fs.Parse(os.Args[1:]); err != nil {
|
||||
log.Fatalf("Error parsing configuration: %v", err)
|
||||
}
|
||||
|
||||
if c.Domain == "" {
|
||||
log.Fatal("You have to supply the domain via env variable DDNS_DOMAIN or command line flag --domain=DOMAIN")
|
||||
|
|
Loading…
Reference in New Issue