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.Logger)
router.Use(middleware.Recoverer) 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 // Setup basic file server nothing fancy
router.Handle("/static/*", http.StripPrefix("/static", http.FileServer(http.Dir("static")))) 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("/register", s.handleRegister())
router.Post("/login", s.handleLogin()) router.Post("/login", s.handleLogin())
router.Post("/logout", s.handleLogout()) router.Post("/logout", s.handleLogout())
router.Post("/refresh", s.handleRefresh())
}) })
// Private routes // Private routes
@@ -31,8 +32,8 @@ func (s *Server) setupRoutes() *chi.Mux {
r.Use(s.hasAuth) r.Use(s.hasAuth)
// TODO add authenicated routes here // TODO add authenicated routes here
// r.Get("/", s.handleHome()) r.Get("/home", s.handleHome())
// router.Mount("/users", s.userRoutes()) // router.Mount("/api", s.apiRoutes())
}) })
return router return router
+1 -1
View File
@@ -7,7 +7,7 @@ import (
"nfeeder/internal/db" "nfeeder/internal/db"
) )
var MAX_USER_SESSIONS = 5 var MAX_USER_SESSIONS = 3
type Server struct { type Server struct {
httpServer *http.Server httpServer *http.Server
+11 -25
View File
@@ -2,38 +2,24 @@ package web
import ( import (
"context" "context"
"html/template" "strconv"
"net/http"
"path/filepath"
) )
func userIDFromContext(ctx context.Context) (string, bool) { func userIDFromContext(ctx context.Context) (int64, bool) {
id, ok := ctx.Value(userIDKey).(string) val := ctx.Value(userIDKey)
return id, ok if val == nil {
return 0, false
} }
// TODO: Not sure this is needed right now strID, ok := val.(string)
// Renders a full page by combining the base template with a page template if !ok {
// Parsed together so the page can define blocks needed for base template return 0, false
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"),
} }
tmpl, err := template.ParseFiles(files...) id, err := strconv.ParseInt(strID, 10, 64)
if err != nil { if err != nil {
http.Error(w, "template error: "+err.Error(), http.StatusInternalServerError) return 0, false
return
} }
w.Header().Set("Content-Type", "text/html") return id, true
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)
} }
+1 -1
View File
@@ -11,7 +11,7 @@ token: jsonpath "$.access_token"
# Step 2: Use the token to access a protected route # Step 2: Use the token to access a protected route
# Hurl automatically handles the variable injection with {{token}} # 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}} Authorization: Bearer {{token}}
HTTP 200 HTTP 200