Files
svg-templater/internal/server/http.go
2026-02-03 00:29:08 +01:00

33 lines
798 B
Go

package server
import (
"fmt"
"log"
"net/http"
"tomatentum.net/svg-templater/internal/routes"
"tomatentum.net/svg-templater/pkg/auth"
)
func PrepareHTTP() {
registerAuthorized("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "You are authorized!")
})
registerAuthorized("/svg/", func(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
}
routes.CreateSVG(w, *r)
})
}
func Start() {
log.Println("Starting http server on :3000")
http.ListenAndServe(":3000", nil)
}
func registerAuthorized(path string, f func(w http.ResponseWriter, r *http.Request)) {
http.HandleFunc(path, auth.AuthMiddleware(http.HandlerFunc(f)))
log.Println("Registered authorized handler for", path)
}