Update favicon handling and bump version to v0.6.1
- main.go - Removed static favicon serving from `ServeMux`. - Removed import for `net/http`. - pkg/version/version - Updated version from v0.6.0 to v0.6.1. - cmd/lerproxy/main.go - Added embedded support for default favicon using `//go:embed`. - Modified logic to serve favicon as an embedded resource or from file in the same directory as the nostr.json - static/favicon.ico - Deleted static favicon file. - cmd/lerproxy/favicon.ico - Added new file for embedded favicon resource.
This commit is contained in:
BIN
cmd/lerproxy/favicon.ico
Normal file
BIN
cmd/lerproxy/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
@@ -6,6 +6,7 @@ package main
|
||||
import (
|
||||
"bufio"
|
||||
"crypto/tls"
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -35,6 +36,9 @@ import (
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
//go:embed favicon.ico
|
||||
var defaultFavicon []byte
|
||||
|
||||
type runArgs struct {
|
||||
Addr string `arg:"-l,--listen" default:":https" help:"address to listen at"`
|
||||
Conf string `arg:"-m,--map" default:"mapping.txt" help:"file with host/backend mapping"`
|
||||
@@ -322,6 +326,19 @@ func setProxy(mapping map[string]string) (h http.Handler, err error) {
|
||||
fmt.Fprint(writer, nostrJSON)
|
||||
},
|
||||
)
|
||||
fin := hn + "/favicon.ico"
|
||||
var fi []byte
|
||||
if fi, err = os.ReadFile(fin); !chk.E(err) {
|
||||
fi = defaultFavicon
|
||||
}
|
||||
mux.HandleFunc(
|
||||
hn+"/favicon.ico",
|
||||
func(writer http.ResponseWriter, request *http.Request) {
|
||||
if _, err = writer.Write(fi); chk.E(err) {
|
||||
return
|
||||
}
|
||||
},
|
||||
)
|
||||
continue
|
||||
}
|
||||
} else if u, err := url.Parse(ba); err == nil {
|
||||
|
||||
9
main.go
9
main.go
@@ -5,7 +5,6 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
"os"
|
||||
|
||||
@@ -78,14 +77,6 @@ func main() {
|
||||
}
|
||||
var opts []options.O
|
||||
serveMux := servemux.NewServeMux()
|
||||
|
||||
// Add favicon handler
|
||||
serveMux.HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "image/x-icon")
|
||||
w.Header().Set("Cache-Control", "public, max-age=86400") // Cache for 24 hours
|
||||
http.ServeFile(w, r, "static/favicon.ico")
|
||||
})
|
||||
|
||||
if server, err = relay.NewServer(
|
||||
serverParams, serveMux, opts...,
|
||||
); chk.E(err) {
|
||||
|
||||
@@ -1 +1 @@
|
||||
v0.6.0
|
||||
v0.6.1
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 432 B |
Reference in New Issue
Block a user