Skip to content

Commit a451608

Browse files
committed
Fix that custom html headers and static assets got lost when converting a Caddyfile to JSON with caddy adapt
1 parent bc6ed1c commit a451608

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

caddyfile_authn_ui.go

+6-17
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"github.com/greenpau/caddy-security/pkg/util"
2121
"github.com/greenpau/go-authcrunch/pkg/authn"
2222
"github.com/greenpau/go-authcrunch/pkg/authn/ui"
23-
"io/ioutil"
2423
"strings"
2524
)
2625

@@ -130,19 +129,7 @@ func parseCaddyfileAuthPortalUI(h *caddyfile.Dispenser, repl *caddy.Replacer, po
130129
case strings.HasPrefix(args, "js"):
131130
portal.UI.CustomJsPath = strings.ReplaceAll(args, "js ", "")
132131
case strings.HasPrefix(args, "html header path"):
133-
args = strings.ReplaceAll(args, "html header path ", "")
134-
b, err := ioutil.ReadFile(args)
135-
if err != nil {
136-
return h.Errf("%s %s subdirective: %s %v", rootDirective, subDirective, args, err)
137-
}
138-
for k, v := range ui.PageTemplates {
139-
headIndex := strings.Index(v, "<meta name=\"description\"")
140-
if headIndex < 1 {
141-
continue
142-
}
143-
v = v[:headIndex] + string(b) + v[headIndex:]
144-
ui.PageTemplates[k] = v
145-
}
132+
portal.UI.CustomHTMLHeaderPath = strings.ReplaceAll(args, "html header path ", "")
146133
case args == "":
147134
return h.Errf("%s %s directive has no value", rootDirective, subDirective)
148135
default:
@@ -161,9 +148,11 @@ func parseCaddyfileAuthPortalUI(h *caddyfile.Dispenser, repl *caddy.Replacer, po
161148
return h.Errf("auth backend %s subdirective %s URI must be prefixed with %s, got %s",
162149
rootDirective, subDirective, prefix, assetURI)
163150
}
164-
if err := ui.StaticAssets.AddAsset(assetURI, assetContentType, assetPath); err != nil {
165-
return h.Errf("auth backend %s subdirective %s failed: %s", rootDirective, subDirective, err)
166-
}
151+
portal.UI.StaticAssets = append(portal.UI.StaticAssets, ui.StaticAsset{
152+
Path: assetURI,
153+
FsPath: assetPath,
154+
ContentType: assetContentType,
155+
})
167156
case "disable":
168157
args := util.FindReplaceAll(repl, h.RemainingArgs())
169158
if err := portal.UI.DisablePage(args); err != nil {

0 commit comments

Comments
 (0)