ai cooking
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

don't match everything more 404 (#517)

Co-authored-by: paul miller <paul.miller>

authored by

Paul Miller
paul miller
and committed by
GitHub
60a86aad 3083da3a

+37 -2
+7
cmd/careme/home.go
··· 9 9 10 10 "careme/internal/auth" 11 11 "careme/internal/locations" 12 + "careme/internal/routing" 12 13 "careme/internal/seasons" 13 14 "careme/internal/templates" 14 15 utypes "careme/internal/users/types" ··· 22 23 GetLocationByID(ctx context.Context, locationID string) (*locations.Location, error) 23 24 } 24 25 authClient auth.AuthClient 26 + } 27 + 28 + func (h home) Register(routes routing.Registrar) { 29 + routes.Handle("/{$}", h) 30 + routes.Handle("/index.html", h) 31 + routes.Handle("/index.htm", h) 25 32 } 26 33 27 34 func (h home) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+1 -1
cmd/careme/web.go
··· 122 122 http.Error(w, "template error", http.StatusInternalServerError) 123 123 } 124 124 }) 125 - appRoutes.Handle("/", home{userStorage, locationStorage, authClient}) 125 + home{userStorage, locationStorage, authClient}.Register(appRoutes) 126 126 127 127 // no logging for readyiness too noisy. 128 128 rootMux.Handle("/ready", &recoverer{ro})
+29 -1
cmd/careme/web_e2e_test.go
··· 174 174 } 175 175 } 176 176 177 + func TestHomeRoutesAreExplicit(t *testing.T) { 178 + srv := newTestServer(t) 179 + defer srv.Close() 180 + 181 + client := newTestClient(t) 182 + 183 + for _, path := range []string{"/", "/index.html", "/index.htm"} { 184 + resp := mustGet(t, client, srv.URL+path) 185 + body := readAll(t, resp.Body) 186 + if err := resp.Body.Close(); err != nil { 187 + t.Fatalf("failed to close response body: %v", err) 188 + } 189 + if resp.StatusCode != http.StatusOK { 190 + t.Fatalf("GET %s expected 200, got %d: %s", path, resp.StatusCode, body) 191 + } 192 + requireValidHTML(t, path, resp.Header.Get("Content-Type"), body) 193 + } 194 + 195 + resp := mustGet(t, client, srv.URL+"/foobar") 196 + body := readAll(t, resp.Body) 197 + if err := resp.Body.Close(); err != nil { 198 + t.Fatalf("failed to close response body: %v", err) 199 + } 200 + if resp.StatusCode != http.StatusNotFound { 201 + t.Fatalf("GET /foobar expected 404, got %d: %s", resp.StatusCode, body) 202 + } 203 + } 204 + 177 205 func newTestServer(t *testing.T) *httptest.Server { 178 206 t.Helper() 179 207 ··· 205 233 utfactory := users.FakeUnsubscribeTokenFactory() 206 234 users.NewHandler(userStorage, locationStorage, mockAuth, utfactory).Register(appRoutes) 207 235 recipes.NewHandler(cfg, userStorage, generator, locationStorage, cacheStore, cacheStore, mockAuth).Register(appRoutes) 208 - appRoutes.Handle("/", home{userStorage, locationStorage, mockAuth}) 236 + home{userStorage, locationStorage, mockAuth}.Register(appRoutes) 209 237 210 238 ro := &readyOnce{} 211 239 ro.add(locationServer)