mirror of
https://github.com/juanfont/headscale.git
synced 2025-11-20 17:56:02 -05:00
hscontrol: convert BlankHandler to use elem-go
This commit is contained in:
committed by
Kristoffer Dalby
parent
75e24de7bd
commit
09c9762fe0
@@ -286,12 +286,16 @@ func FaviconHandler(writer http.ResponseWriter, req *http.Request) {
|
|||||||
http.ServeContent(writer, req, "favicon.ico", time.Unix(0, 0), bytes.NewReader(favicon))
|
http.ServeContent(writer, req, "favicon.ico", time.Unix(0, 0), bytes.NewReader(favicon))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a blank page with favicon linked.
|
// BlankHandler returns a blank page with favicon linked.
|
||||||
func BlankHandler(writer http.ResponseWriter, res *http.Request) {
|
func BlankHandler(writer http.ResponseWriter, res *http.Request) {
|
||||||
writer.Header().Set("Content-Type", "text/html; charset=utf-8")
|
writer.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
io.WriteString(writer, `
|
writer.WriteHeader(http.StatusOK)
|
||||||
<!doctype html><html><head>
|
|
||||||
<link rel="icon" href="/favicon.ico">
|
_, err := writer.Write([]byte(templates.BlankPage().Render()))
|
||||||
</head><body></body></html>
|
if err != nil {
|
||||||
`)
|
log.Error().
|
||||||
|
Caller().
|
||||||
|
Err(err).
|
||||||
|
Msg("Failed to write HTTP response")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,8 +14,6 @@ var headscaleCSS string
|
|||||||
//go:embed headscale.svg
|
//go:embed headscale.svg
|
||||||
var headscaleSVG string
|
var headscaleSVG string
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// mdTypesetBody creates a body element with md-typeset styling
|
// mdTypesetBody creates a body element with md-typeset styling
|
||||||
// that matches the official Headscale documentation design.
|
// that matches the official Headscale documentation design.
|
||||||
// Uses CSS classes with styles defined in headscaleCSS.
|
// Uses CSS classes with styles defined in headscaleCSS.
|
||||||
@@ -206,3 +204,20 @@ func HtmlStructure(head, body *elem.Element) *elem.Element {
|
|||||||
body,
|
body,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BlankPage creates a minimal blank HTML page with favicon.
|
||||||
|
// Used for endpoints that need to return a valid HTML page with no content.
|
||||||
|
func BlankPage() *elem.Element {
|
||||||
|
return elem.Html(attrs.Props{attrs.Lang: "en"},
|
||||||
|
elem.Head(nil,
|
||||||
|
elem.Meta(attrs.Props{
|
||||||
|
attrs.Charset: "UTF-8",
|
||||||
|
}),
|
||||||
|
elem.Link(attrs.Props{
|
||||||
|
attrs.Rel: "icon",
|
||||||
|
attrs.Href: "/favicon.ico",
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
elem.Body(nil),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user