High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.
JavaScript campaigncampaign-managementemail-marketingemail-subscriptionlistmonkmailing-listnewsletternewsletter-managementnewsletter-softwareself-hostedsms-gatewaysmtptransactional-emails
Fix echo's URI routing race condition that caused random 404s.
Kailash Nadh1e8b533d45ad
diff --git a/cmd/campaigns.go b/cmd/campaigns.goindex 55d97421..b3b66beb 100644--- a/cmd/campaigns.go+++ b/cmd/campaigns.go@@ -267,9 +267,9 @@ func handleCreateCampaign(c echo.Context) error {}// Hand over to the GET handler to return the last insertion.- c.SetParamNames("id")- c.SetParamValues(fmt.Sprintf("%d", newID))- return handleGetCampaigns(c)+ return handleGetCampaigns(copyEchoCtx(c, map[string]string{+ "id": fmt.Sprintf("%d", newID),+ }))}// handleUpdateCampaign handles campaign modification.diff --git a/cmd/handlers.go b/cmd/handlers.goindex e46dd9ed..b699854e 100644--- a/cmd/handlers.go+++ b/cmd/handlers.go@@ -238,3 +238,23 @@ func getPagination(q url.Values, perPage, maxPerPage int) pagination {Limit: perPage,}}++// copyEchoCtx returns a copy of the the current echo.Context in a request+// with the given params set for the active handler to proxy the request+// to another handler without mutating its context.+func copyEchoCtx(c echo.Context, params map[string]string) echo.Context {+ var (+ keys = make([]string, 0, len(params))+ vals = make([]string, 0, len(params))+ )+ for k, v := range params {+ keys = append(keys, k)+ vals = append(vals, v)+ }++ b := c.Echo().NewContext(c.Request(), c.Response())+ b.Set("app", c.Get("app").(*App))+ b.SetParamNames(keys...)+ b.SetParamValues(vals...)+ return b+}diff --git a/cmd/lists.go b/cmd/lists.goindex ad5639d2..9c3c20a9 100644--- a/cmd/lists.go+++ b/cmd/lists.go@@ -118,9 +118,9 @@ func handleCreateList(c echo.Context) error {}// Hand over to the GET handler to return the last insertion.- c.SetParamNames("id")- c.SetParamValues(fmt.Sprintf("%d", newID))- return handleGetLists(c)+ return handleGetLists(copyEchoCtx(c, map[string]string{+ "id": fmt.Sprintf("%d", newID),+ }))}// handleUpdateList handles list modification.diff --git a/cmd/templates.go b/cmd/templates.goindex c0b24b90..b31aa270 100644--- a/cmd/templates.go+++ b/cmd/templates.go@@ -147,9 +147,9 @@ func handleCreateTemplate(c echo.Context) error {}// Hand over to the GET handler to return the last insertion.- c.SetParamNames("id")- c.SetParamValues(fmt.Sprintf("%d", newID))- return handleGetTemplates(c)+ return handleGetTemplates(copyEchoCtx(c, map[string]string{+ "id": fmt.Sprintf("%d", newID),+ }))}// handleUpdateTemplate handles template modification.