#109 basic infrastructure for server side rendering with templ

This commit is contained in:
Tim
2024-08-22 22:53:28 +02:00
parent 32c4da0f93
commit 62dd3b539f
12 changed files with 82 additions and 31 deletions

24
handler.go Normal file
View File

@@ -0,0 +1,24 @@
package main
import (
"me-fit/middleware"
"me-fit/service"
"database/sql"
"net/http"
)
func getHandler(db *sql.DB) http.Handler {
var router = http.NewServeMux()
router.HandleFunc("/", service.HandleStaticUi)
// Serve static files (CSS, JS and images)
router.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("./static/"))))
router.HandleFunc("POST /api/workout", service.NewWorkout(db))
router.HandleFunc("GET /api/workout", service.GetWorkouts(db))
router.HandleFunc("DELETE /api/workout", service.DeleteWorkout(db))
return middleware.Logging(middleware.EnableCors(router))
}