diff --git a/main.go b/main.go index 16ed52a..2f7df81 100644 --- a/main.go +++ b/main.go @@ -38,12 +38,16 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) { func RegisterRoutes(r *mux.Router, pipelines []pipelines.IPipeline, storageProvider storage.IStorageProvider) { r.HandleFunc("/", IndexHandler) - - for _, pipeline := range pipelines { - r.HandleFunc("/"+pipeline.GetSlug(), func(w http.ResponseWriter, r *http.Request) { - PipelineHandler(pipeline, storageProvider, w, r) - }) - } + r.HandleFunc("/pipelines/{pipeline}", func(w http.ResponseWriter, r *http.Request) { + for _, pipeline := range pipelines { + if pipeline.GetSlug() == mux.Vars(r)["pipeline"] { + PipelineHandler(pipeline, storageProvider, w, r) + return + } + } + + w.WriteHeader(404) + }) } func main() { diff --git a/main_test.go b/main_test.go index cd2b0c1..e97f4ef 100644 --- a/main_test.go +++ b/main_test.go @@ -36,7 +36,7 @@ func TestEndpointRoute(t *testing.T) { RegisterRoutes(router, []pipelines.IPipeline{data}, fs) - request, _ := http.NewRequest("GET", "/"+data.Slug, nil) + request, _ := http.NewRequest("GET", "/pipelines/"+data.Slug, nil) responseRecorder := httptest.NewRecorder() router.ServeHTTP(responseRecorder, request) @@ -49,7 +49,7 @@ func TestEndpointRoute(t *testing.T) { t.Run("Unregistered pipelines return 404", func(t *testing.T) { router := mux.NewRouter() - request, _ := http.NewRequest("GET", "/"+data.Slug, nil) + request, _ := http.NewRequest("GET", "/pipelines/"+data.Slug, nil) responseRecorder := httptest.NewRecorder() router.ServeHTTP(responseRecorder, request)