43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
"regexp"
|
|
|
|
blockthingsmiddleware "gitlab.com/mstarongitlab/block-things-middleware"
|
|
|
|
"gitlab.com/mstarongitlab/linstrom/server/middlewares"
|
|
"gitlab.com/mstarongitlab/linstrom/storage"
|
|
)
|
|
|
|
type Server struct {
|
|
handler http.Handler
|
|
}
|
|
|
|
func NewServer(store *storage.Storage) *Server {
|
|
handler := http.NewServeMux()
|
|
handler.HandleFunc("/.well-known/webfinger", webfingerHandler)
|
|
// handler.Handle("/api/", http.StripPrefix("/ap", buildApiRouter()))
|
|
handler.HandleFunc("/notes/{id}", notesWebFrontendHandler)
|
|
handler.HandleFunc("/@{id}", accountWebFrontendHandler)
|
|
|
|
withMiddlewares := middlewares.ChainMiddlewares(
|
|
handler,
|
|
middlewares.InjectLoggerMiddleware,
|
|
middlewares.InjectStorageMiddlewareBuilder(store),
|
|
middlewares.InjectContextValuesBuilder(map[middlewares.ContextKey]any{
|
|
middlewares.CONTEXT_KEY_STORAGE: store,
|
|
}),
|
|
|
|
blockthingsmiddleware.BuildMiddleware(blockthingsmiddleware.Config{
|
|
UserAgentRegexes: []*regexp.Regexp{
|
|
regexp.MustCompile("ArchiveBot"),
|
|
regexp.MustCompile("GPTBot"),
|
|
},
|
|
CheckDomain: false,
|
|
}),
|
|
)
|
|
return &Server{
|
|
handler: withMiddlewares,
|
|
}
|
|
}
|