rm -r --cached pkg/web

This commit is contained in:
viljarb
2026-02-18 20:48:30 +01:00
parent a6ec856759
commit 77dd155299
37 changed files with 0 additions and 3558 deletions

View File

@@ -1,59 +0,0 @@
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: /"))
})
}

View File

@@ -1,32 +0,0 @@
package server
import (
"embed"
"net/http"
"time"
"github.com/LazyBachelor/LazyPM/internal/service"
)
type Server struct {
Address string
Assets embed.FS
Services *service.Services
}
// NewServer creates and configures a new HTTP server instance.
func NewServer(props Server) *http.Server {
if props.Address == "" {
props.Address = ":8080"
}
handler := props.RegisterRoutes(props.Assets)
return &http.Server{
Addr: props.Address,
Handler: handler,
IdleTimeout: time.Minute,
ReadTimeout: time.Second * 10,
WriteTimeout: time.Second * 10,
}
}