Skip to content
Open

testing #3336

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions src/frontend/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (fe *frontendServer) addToCartHandler(w http.ResponseWriter, r *http.Reques
renderHTTPError(log, r, w, errors.Wrap(err, "failed to add to cart"), http.StatusInternalServerError)
return
}
w.Header().Set("location", baseUrl + "/cart")
w.Header().Set("location", baseUrl+"/cart")
w.WriteHeader(http.StatusFound)
}

Expand All @@ -244,7 +244,7 @@ func (fe *frontendServer) emptyCartHandler(w http.ResponseWriter, r *http.Reques
renderHTTPError(log, r, w, errors.Wrap(err, "failed to empty cart"), http.StatusInternalServerError)
return
}
w.Header().Set("location", baseUrl + "/")
w.Header().Set("location", baseUrl+"/")
w.WriteHeader(http.StatusFound)
}

Expand Down Expand Up @@ -401,6 +401,7 @@ func (fe *frontendServer) placeOrderHandler(w http.ResponseWriter, r *http.Reque
}

func (fe *frontendServer) assistantHandler(w http.ResponseWriter, r *http.Request) {
log := r.Context().Value(ctxKeyLog{}).(logrus.FieldLogger)
currencies, err := fe.getCurrencies(r.Context())
if err != nil {
renderHTTPError(log, r, w, errors.Wrap(err, "could not retrieve currencies"), http.StatusInternalServerError)
Expand All @@ -415,6 +416,29 @@ func (fe *frontendServer) assistantHandler(w http.ResponseWriter, r *http.Reques
}
}

func (fe *frontendServer) aboutHandler(w http.ResponseWriter, r *http.Request) {
log := r.Context().Value(ctxKeyLog{}).(logrus.FieldLogger)
currencies, err := fe.getCurrencies(r.Context())
if err != nil {
renderHTTPError(log, r, w, errors.Wrap(err, "could not retrieve currencies"), http.StatusInternalServerError)
return
}

cart, err := fe.getCart(r.Context(), sessionID(r))
if err != nil {
renderHTTPError(log, r, w, errors.Wrap(err, "could not retrieve cart"), http.StatusInternalServerError)
return
}

if err := templates.ExecuteTemplate(w, "about", injectCommonTemplateData(r, map[string]interface{}{
"show_currency": true,
"currencies": currencies,
"cart_size": cartSize(cart),
})); err != nil {
log.Println(err)
}
}

func (fe *frontendServer) logoutHandler(w http.ResponseWriter, r *http.Request) {
log := r.Context().Value(ctxKeyLog{}).(logrus.FieldLogger)
log.Debug("logging out")
Expand All @@ -423,7 +447,7 @@ func (fe *frontendServer) logoutHandler(w http.ResponseWriter, r *http.Request)
c.MaxAge = -1
http.SetCookie(w, c)
}
w.Header().Set("Location", baseUrl + "/")
w.Header().Set("Location", baseUrl+"/")
w.WriteHeader(http.StatusFound)
}

Expand Down
1 change: 1 addition & 0 deletions src/frontend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ func main() {
r.HandleFunc(baseUrl+"/logout", svc.logoutHandler).Methods(http.MethodGet)
r.HandleFunc(baseUrl+"/cart/checkout", svc.placeOrderHandler).Methods(http.MethodPost)
r.HandleFunc(baseUrl+"/assistant", svc.assistantHandler).Methods(http.MethodGet)
r.HandleFunc(baseUrl+"/about", svc.aboutHandler).Methods(http.MethodGet, http.MethodHead)
r.PathPrefix(baseUrl + "/static/").Handler(http.StripPrefix(baseUrl+"/static/", http.FileServer(http.Dir("./static/"))))
r.HandleFunc(baseUrl+"/robots.txt", func(w http.ResponseWriter, _ *http.Request) { fmt.Fprint(w, "User-agent: *\nDisallow: /") })
r.HandleFunc(baseUrl+"/_healthz", func(w http.ResponseWriter, _ *http.Request) { fmt.Fprint(w, "ok") })
Expand Down
30 changes: 30 additions & 0 deletions src/frontend/templates/about.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!--
Copyright 2026
-->

{{ define "about" }}

{{ template "header" . }}
<main role="main" class="home">
<div class="container py-5">
<div class="row justify-content-center">
<div class="col-12 col-lg-8">
<h1 class="mb-4">About This Demo Store</h1>
<p>
This storefront is part of the microservices demo application. It showcases a
production-style architecture where independent services collaborate to provide
product browsing, cart management, checkout, recommendations, and supporting
functionality.
</p>
<p>
The site is intended for demonstration and learning purposes only. No real
purchases are processed.
</p>
<a href="{{ $.baseUrl }}/" class="btn btn-dark mt-3">Back to shopping</a>
</div>
</div>
</div>
</main>
{{ template "footer" . }}

{{ end }}
1 change: 1 addition & 0 deletions src/frontend/templates/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
{{ end }}
</a>
<div class="controls">
<a href="{{ $.baseUrl }}/about" class="text-reset mr-3 d-none d-md-inline-block">About</a>

{{ if $.show_currency }}
<div class="h-controls">
Expand Down