🏗️ Connect and use webfinger module

This commit is contained in:
Maxim Lebedev 2024-02-14 12:16:45 +06:00
parent d4a7d8061d
commit c359d05761
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
1 changed files with 17 additions and 2 deletions

View File

@ -32,6 +32,8 @@ import (
themefsrepo "source.toby3d.me/toby3d/home/internal/theme/repository/fs"
themeucase "source.toby3d.me/toby3d/home/internal/theme/usecase"
"source.toby3d.me/toby3d/home/internal/urlutil"
webfingerhttpdelivery "source.toby3d.me/toby3d/home/internal/webfinger/delivery/http"
webfingerucase "source.toby3d.me/toby3d/home/internal/webfinger/usecase"
)
type App struct {
@ -58,7 +60,21 @@ func NewApp(logger *log.Logger, config *domain.Config) (*App, error) {
entries := pagefsrepo.NewFileSystemPageRepository(contentDir)
entrier := pageucase.NewEntryUseCase(entries, resources)
serverer := servercase.NewServerUseCase(sites)
webfingerer := webfingerucase.NewWebFingerUseCase(sites)
webfingerHandler := webfingerhttpdelivery.NewHandler(webfingerer)
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
head, tail := urlutil.ShiftPath(r.URL.Path)
switch head {
case ".well-known":
switch {
case strings.HasPrefix(tail, "/webfinger"):
webfingerHandler.ServeHTTP(w, r)
return
}
}
// NOTE(toby3d): any static file is public and unprotected by
// design, so it's safe to search it first before deep down to
// any page or it's resource which might be protected by
@ -83,8 +99,7 @@ func NewApp(logger *log.Logger, config *domain.Config) (*App, error) {
if s.IsMultiLingual() {
// NOTE(toby3d): $HOME_CONTENT_DIR contains at least two
// index.md with different language codes.
head, tail := urlutil.ShiftPath(r.URL.Path)
if head == "" {
if head, tail = urlutil.ShiftPath(r.URL.Path); head == "" {
// NOTE(toby3d): client request just '/', try to
// understand which language subdirectory is
// need to redirect.