foxfiles/web.go
2024-02-01 21:32:10 +01:00

33 lines
699 B
Go

package main
import (
"fmt"
"net/http"
"codeberg.org/u1f320/foxfiles/frontend"
"codeberg.org/u1f320/foxfiles/log"
"github.com/go-chi/chi/v5"
)
func Router() (chi.Router, error) {
r := chi.NewRouter()
glue, err := frontend.Glue(true)
if err != nil {
return nil, fmt.Errorf("creating frontend glue: %w", err)
}
glueFileServer, err := glue.FileServer()
if err != nil {
return nil, fmt.Errorf("creating glue file server: %w", err)
}
r.Handle("/src/*", glueFileServer)
r.HandleFunc("/app", func(w http.ResponseWriter, r *http.Request) {
err := frontend.Template.Execute(w, glue)
if err != nil {
log.Errorf("executing index.html template: %v", err)
}
})
return r, nil
}