support .well-known dir

This commit is contained in:
Ronmi Ren 2025-01-08 05:59:50 +08:00
commit 07d12326f0
2 changed files with 15 additions and 3 deletions

View file

@ -54,13 +54,24 @@ func (f *Forgejo) GetFile(ctx context.Context, headers map[string]string, user,
return resp, nil
}
func UseAPI(bind string, f *Forgejo) (*http.Server, error) {
func UseAPI(bind, wellKnown string, f *Forgejo) (*http.Server, error) {
if f == nil {
return nil, errors.New("forgejo is nil")
}
mux := http.NewServeMux()
if wellKnown != "" {
mux.Handle(
"/.well-known/",
http.StripPrefix(
"/.well-known/",
http.FileServer(http.Dir(wellKnown)),
),
)
}
mux.HandleFunc("/", f.handle)
s := &http.Server{
Addr: bind,
Handler: http.HandlerFunc(f.handle),
Handler: mux,
}
return s, nil
}