progress
server is launchable and passkey support works
This commit is contained in:
parent
ee172d84a8
commit
c572066571
21 changed files with 857 additions and 40 deletions
41
server/server.go
Normal file
41
server/server.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
|
||||
"github.com/mstarongithub/passkey"
|
||||
"github.com/rs/zerolog/log"
|
||||
"gitlab.com/mstarongitlab/linstrom/storage"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
store *storage.Storage
|
||||
router http.Handler
|
||||
}
|
||||
|
||||
func NewServer(store *storage.Storage, pkey *passkey.Passkey, reactiveFS, staticFS fs.FS) *Server {
|
||||
handler := buildRootHandler(pkey, reactiveFS, staticFS)
|
||||
handler = ChainMiddlewares(handler, LoggingMiddleware, ContextValsMiddleware(map[any]any{}))
|
||||
return &Server{
|
||||
store: store,
|
||||
router: handler,
|
||||
}
|
||||
}
|
||||
|
||||
func buildRootHandler(pkey *passkey.Passkey, reactiveFS, staticFS fs.FS) http.Handler {
|
||||
mux := http.NewServeMux()
|
||||
pkey.MountRoutes(mux, "/webauthn/")
|
||||
mux.Handle("/", http.FileServerFS(reactiveFS))
|
||||
mux.Handle("/nojs/", http.StripPrefix("/nojs", http.FileServerFS(staticFS)))
|
||||
mux.Handle("/pk/", http.StripPrefix("/pk", http.FileServer(http.Dir("pk-auth"))))
|
||||
mux.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, true) })
|
||||
|
||||
return mux
|
||||
}
|
||||
|
||||
func (s *Server) Start(addr string) {
|
||||
log.Info().Str("addr", addr).Msg("Starting server")
|
||||
http.ListenAndServe(addr, s.router)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue