33 lines
617 B
Go
33 lines
617 B
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
"path/filepath"
|
|
|
|
"git.oblat.lv/alex/triggerssmith/internal/config"
|
|
"github.com/go-chi/chi/v5"
|
|
)
|
|
|
|
type Router struct {
|
|
r chi.Router
|
|
|
|
cfg *config.Config
|
|
}
|
|
|
|
func NewRouter(cfg *config.Config) *Router {
|
|
r := chi.NewRouter()
|
|
return &Router{
|
|
r: r,
|
|
cfg: cfg,
|
|
}
|
|
}
|
|
|
|
func (r *Router) RouteHandler() chi.Router {
|
|
r.r.Get("/", func(w http.ResponseWriter, req *http.Request) {
|
|
http.ServeFile(w, req, filepath.Join(r.cfg.Server.StaticFilesPath, "index.html"))
|
|
})
|
|
fs := http.FileServer(http.Dir("static"))
|
|
r.r.Handle("/static/*", http.StripPrefix("/static/", fs))
|
|
return r.r
|
|
}
|