From e0c2bf08b42951707d0a82c26083c0da26f0e6dd Mon Sep 17 00:00:00 2001 From: Jason Hilder Date: Thu, 30 Apr 2026 08:39:31 +0200 Subject: [PATCH] Updated to be correct port. --- internal/web/routes.go | 7 ++++--- internal/web/server.go | 2 +- internal/web/utils.go | 40 +++++++++++++-------------------------- test_requests/access.hurl | 2 +- 4 files changed, 19 insertions(+), 32 deletions(-) diff --git a/internal/web/routes.go b/internal/web/routes.go index b595f6e..7caef9b 100644 --- a/internal/web/routes.go +++ b/internal/web/routes.go @@ -13,7 +13,7 @@ func (s *Server) setupRoutes() *chi.Mux { router.Use(middleware.Logger) router.Use(middleware.Recoverer) - // TODO: Not sure this is needed right now + // TODO: CLEANUP: Not sure this is needed right now // Setup basic file server nothing fancy router.Handle("/static/*", http.StripPrefix("/static", http.FileServer(http.Dir("static")))) @@ -23,6 +23,7 @@ func (s *Server) setupRoutes() *chi.Mux { router.Post("/register", s.handleRegister()) router.Post("/login", s.handleLogin()) router.Post("/logout", s.handleLogout()) + router.Post("/refresh", s.handleRefresh()) }) // Private routes @@ -31,8 +32,8 @@ func (s *Server) setupRoutes() *chi.Mux { r.Use(s.hasAuth) // TODO add authenicated routes here - // r.Get("/", s.handleHome()) - // router.Mount("/users", s.userRoutes()) + r.Get("/home", s.handleHome()) + // router.Mount("/api", s.apiRoutes()) }) return router diff --git a/internal/web/server.go b/internal/web/server.go index 5ed9a45..5c4a4a0 100644 --- a/internal/web/server.go +++ b/internal/web/server.go @@ -7,7 +7,7 @@ import ( "nfeeder/internal/db" ) -var MAX_USER_SESSIONS = 5 +var MAX_USER_SESSIONS = 3 type Server struct { httpServer *http.Server diff --git a/internal/web/utils.go b/internal/web/utils.go index 9573613..e0646a0 100644 --- a/internal/web/utils.go +++ b/internal/web/utils.go @@ -2,38 +2,24 @@ package web import ( "context" - "html/template" - "net/http" - "path/filepath" + "strconv" ) -func userIDFromContext(ctx context.Context) (string, bool) { - id, ok := ctx.Value(userIDKey).(string) - return id, ok -} - -// TODO: Not sure this is needed right now -// Renders a full page by combining the base template with a page template -// Parsed together so the page can define blocks needed for base template -func render(w http.ResponseWriter, _ *http.Request, page string, data any) { - files := []string{ - filepath.Join("internal", "templates", "layouts", "base.html"), - filepath.Join("internal", "templates", "pages", page+".html"), +func userIDFromContext(ctx context.Context) (int64, bool) { + val := ctx.Value(userIDKey) + if val == nil { + return 0, false } - tmpl, err := template.ParseFiles(files...) + strID, ok := val.(string) + if !ok { + return 0, false + } + + id, err := strconv.ParseInt(strID, 10, 64) if err != nil { - http.Error(w, "template error: "+err.Error(), http.StatusInternalServerError) - return + return 0, false } - w.Header().Set("Content-Type", "text/html") - - if err := tmpl.ExecuteTemplate(w, "base", data); err != nil { - http.Error(w, "render error: "+err.Error(), http.StatusInternalServerError) - } -} - -func view(w http.ResponseWriter, r *http.Request, page string, data any) { - render(w, r, page, data) + return id, true } diff --git a/test_requests/access.hurl b/test_requests/access.hurl index 6fa69e1..a8e7b3d 100644 --- a/test_requests/access.hurl +++ b/test_requests/access.hurl @@ -11,7 +11,7 @@ token: jsonpath "$.access_token" # Step 2: Use the token to access a protected route # Hurl automatically handles the variable injection with {{token}} -GET http://localhost:8080/api/protected-route +GET http://localhost:3333/api/protected-route Authorization: Bearer {{token}} HTTP 200