Set URL after loading database

This commit is contained in:
2024-11-15 11:55:31 -07:00
parent 0bab92db02
commit beef4523c2
4 changed files with 91 additions and 41 deletions

View File

@ -14,13 +14,11 @@ import (
/*
Create a new chi router, configure it and return it.
*/
func NewChiRouter() *chi.Mux {
func NewChiRouter(port string) *chi.Mux {
r := chi.NewRouter()
// Useful middleware, see : https://pkg.go.dev/github.com/go-chi/httplog/v2@v2.1.1#NewLogger
logger := httplog.NewLogger("app-logger", httplog.Options{
// All log
LogLevel: slog.LevelInfo,
Concise: true,
})
@ -40,29 +38,23 @@ func NewChiRouter() *chi.Mux {
})
*/
// Serve static files.
r.Handle("/static/*", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
// Home page
r.Get("/splash", func(w http.ResponseWriter, r *http.Request) {
slog.Info("we splashin")
HXRender(w, r, pages.Splash)
})
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
// Render home page
slog.Info("we homies")
HXRender(w, r, pages.HomePage)
// 200 OK status
w.WriteHeader(http.StatusOK)
})
// Hello page
r.Get("/hello", func(w http.ResponseWriter, r *http.Request) {
// Render hello
HXRender(w, r, components.HelloWorld)
// 200 OK status
w.WriteHeader(http.StatusOK)
})
// Listen to port 3000.
go http.ListenAndServe(":9245", r)
go http.ListenAndServe(":"+port, r)
return r
}