Files
LazyPM/pkg/web/server/routes.go
viljarb 1d92041538 modified: web/assets/css/styles.css
modified:   web/components/base/input.templ
	modified:   web/components/base/input_templ.go
	modified:   web/components/base/range.templ
	modified:   web/components/base/range_templ.go
	modified:   web/components/base/select.templ
	modified:   web/components/base/select_templ.go
	modified:   web/components/base/textarea.templ
	modified:   web/components/base/textarea_templ.go
	modified:   web/components/icons.templ
	modified:   web/components/icons_templ.go
	modified:   web/components/issue.templ
	modified:   web/components/issue_templ.go
	modified:   web/components/layout.templ
	modified:   web/components/layout_templ.go
	new file:   web/components/sidebar.templ
	new file:   web/components/sidebar_templ.go
	new file:   web/components/status.templ
	new file:   web/components/status_templ.go
	modified:   web/handler/issues.go
	new file:   web/handler/task.go
	modified:   web/input.css
	deleted:    web/package-lock.json
	deleted:    web/package.json
	modified:   web/routes/layout.templ
	modified:   web/routes/layout_templ.go
	modified:   web/server/routes.go
	modified:   web/server/server.go
	modified:   web/web.go
2026-02-18 20:41:52 +01:00

60 lines
1.5 KiB
Go

package server
import (
"embed"
"net/http"
"strings"
"time"
"github.com/LazyBachelor/LazyPM/pkg/web/handler"
"github.com/NYTimes/gziphandler"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"github.com/rs/cors"
)
func (s *Server) RegisterRoutes(assets embed.FS) http.Handler {
r := chi.NewRouter()
r.Use(middleware.Logger)
r.Use(middleware.Recoverer)
r.Use(cors.AllowAll().Handler)
r.Use(middleware.CleanPath)
r.Use(handler.HTMXMiddleware)
r.Use(handler.ServicesMiddleware(s.Services))
s.handleAssets(r, assets)
r.Get("/", handler.IndexHandler)
r.Get("/status", handler.HandleTaskStatus)
r.Route("/issues", func(r chi.Router) {
r.Get("/", handler.ListIssues)
r.Post("/", handler.CreateIssue)
r.Route("/{id}", func(r chi.Router) {
r.Use(handler.IssueCtx)
r.Get("/", handler.GetIssue)
r.Patch("/", handler.UpdateIssue)
r.Delete("/", handler.DeleteIssue)
})
})
return gziphandler.GzipHandler(r)
}
func (s *Server) handleAssets(r chi.Router, assets embed.FS) {
fileServer := http.FileServer(http.Dir("pkg/web/assets"))
r.Handle("/assets/*",
http.StripPrefix("/assets/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "public, max-age=31536000, immutable")
fileServer.ServeHTTP(w, r)
})))
r.Get("/robots.txt", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "no-cache")
http.ServeContent(w, r, "robots.txt", time.Now(), strings.NewReader("User-agent: *\nAllow: /"))
})
}