package handlers

import (
	"net/http"

	"git.haelnorr.com/h/oslstats/internal/view/page"

	"git.haelnorr.com/h/golib/hws"
)

// Handles responses to the / path. Also serves a 404 Page for paths that
// don't have explicit handlers
func Index(server *hws.Server) http.Handler {
	return http.HandlerFunc(
		func(w http.ResponseWriter, r *http.Request) {
			if r.URL.Path != "/" {
				throwNotFound(server, w, r, r.URL.Path)
			}
			page.Index().Render(r.Context(), w)
		},
	)
}
