- Add proxy endpoint for proxying a message to a target's inbox - Change duck embed to fs based to fix mk not understanding it
This commit is contained in:
parent
d70786439e
commit
415cd89792
8 changed files with 104 additions and 17 deletions
|
@ -44,8 +44,6 @@ func BuildAuthorizedFetchCheck(forNonGet bool, forGet bool) webutils.HandlerBuil
|
|||
return func(h http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
log := hlog.FromRequest(r)
|
||||
log.Info().Msg("AuthFetch middleware")
|
||||
defer log.Info().Msg("AuhFetch completed")
|
||||
path := r.URL.Path
|
||||
// Check always open path first
|
||||
for _, re := range publicPaths {
|
||||
|
|
|
@ -29,6 +29,7 @@ package webpublic
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
|
||||
webutils "git.mstar.dev/mstar/goutils/http"
|
||||
|
@ -41,7 +42,7 @@ type Server struct {
|
|||
server *http.Server
|
||||
}
|
||||
|
||||
func New(addr string, duckImg *string) *Server {
|
||||
func New(addr string, duckImg *string, duckFs fs.FS) *Server {
|
||||
handler := http.NewServeMux()
|
||||
handler.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(500)
|
||||
|
@ -53,11 +54,8 @@ func New(addr string, duckImg *string) *Server {
|
|||
handler.HandleFunc("GET /nodeinfo/2.1", api.NodeInfo21)
|
||||
handler.HandleFunc("GET /nodeinfo/2.0", api.NodeInfo20)
|
||||
handler.HandleFunc("GET /errors/{name}", errorTypeHandler)
|
||||
handler.HandleFunc("GET /default-image", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Add("Content-Type", "image/web")
|
||||
w.Header().Add("Content-Disposition", "attachment; filename=\"duck.webp\"")
|
||||
fmt.Fprint(w, *duckImg)
|
||||
})
|
||||
handler.HandleFunc("GET /default-image", buildServeDefaultImage(duckImg, duckFs))
|
||||
handler.HandleFunc("GET /default-image.webp", buildServeDefaultImage(duckImg, duckFs))
|
||||
server := http.Server{
|
||||
Handler: webutils.ChainMiddlewares(
|
||||
handler,
|
||||
|
@ -76,3 +74,15 @@ func (s *Server) Start() error {
|
|||
func (s *Server) Stop() error {
|
||||
return s.server.Shutdown(context.Background())
|
||||
}
|
||||
|
||||
func buildServeDefaultImage(
|
||||
duckImg *string,
|
||||
duckFs fs.FS,
|
||||
) func(w http.ResponseWriter, r *http.Request) {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
http.ServeFileFS(w, r, duckFs, "duck.webp")
|
||||
// w.Header().Add("Content-Type", "image/webp")
|
||||
// w.Header().Add("Content-Disposition", "attachment; filename=\"duck.webp\"")
|
||||
// fmt.Fprint(w, *duckImg)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue