Updated to be correct port.

This commit is contained in:
2026-04-30 08:39:31 +02:00
parent 96dd5c863e
commit e0c2bf08b4
4 changed files with 19 additions and 32 deletions
+4 -3
View File
@@ -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
+1 -1
View File
@@ -7,7 +7,7 @@ import (
"nfeeder/internal/db"
)
var MAX_USER_SESSIONS = 5
var MAX_USER_SESSIONS = 3
type Server struct {
httpServer *http.Server
+11 -25
View File
@@ -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
func userIDFromContext(ctx context.Context) (int64, bool) {
val := ctx.Value(userIDKey)
if val == nil {
return 0, false
}
// 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"),
strID, ok := val.(string)
if !ok {
return 0, false
}
tmpl, err := template.ParseFiles(files...)
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
}
+1 -1
View File
@@ -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