Skip to content

Commit

Permalink
fix: 🐛 add a timeout context to the render function (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
HannesOberreiter authored Jun 10, 2024
1 parent abc4ebe commit 1e86642
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,10 @@ func cronFetch() {

// Utility function to render a template
func render(c echo.Context, status int, t templ.Component) error {
ctx, cancel := context.WithTimeout(c.Request().Context(), 25*time.Second)
defer cancel()
c.Response().Writer.WriteHeader(status)
err := t.Render(context.Background(), c.Response().Writer)
err := t.Render(ctx, c.Response().Writer)
if err != nil {
return c.String(http.StatusInternalServerError, "failed to render response template")
}
Expand Down

0 comments on commit 1e86642

Please sign in to comment.