From 579001059acff9abc9580c57b9aaf35fe796e404 Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Thu, 3 Mar 2016 10:34:07 +0000 Subject: [PATCH] Add pipe/{pipeID}/check endpoint --- app/pipes.go | 16 ++++++++++++++++ client/app/scripts/utils/web-api-utils.js | 6 +++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/pipes.go b/app/pipes.go index c4724a360..8da9e9431 100644 --- a/app/pipes.go +++ b/app/pipes.go @@ -12,6 +12,10 @@ import ( // RegisterPipeRoutes registers the pipe routes func RegisterPipeRoutes(router *mux.Router, pr PipeRouter) { + router.Methods("GET"). + Path("/api/pipe/{pipeID}/check"). + HandlerFunc(requestContextDecorator(checkPipe(pr, UIEnd))) + router.Methods("GET"). Path("/api/pipe/{pipeID}"). HandlerFunc(requestContextDecorator(handlePipeWs(pr, UIEnd))) @@ -25,6 +29,18 @@ func RegisterPipeRoutes(router *mux.Router, pr PipeRouter) { HandlerFunc(requestContextDecorator(deletePipe(pr))) } +func checkPipe(pr PipeRouter, end End) CtxHandlerFunc { + return func(ctx context.Context, w http.ResponseWriter, r *http.Request) { + id := mux.Vars(r)["pipeID"] + _, _, ok := pr.Get(ctx, id, end) + if !ok { + http.NotFound(w, r) + return + } + defer pr.Release(ctx, id, end) + } +} + func handlePipeWs(pr PipeRouter, end End) CtxHandlerFunc { return func(ctx context.Context, w http.ResponseWriter, r *http.Request) { id := mux.Vars(r)["pipeID"] diff --git a/client/app/scripts/utils/web-api-utils.js b/client/app/scripts/utils/web-api-utils.js index f9a2f977d..deacca699 100644 --- a/client/app/scripts/utils/web-api-utils.js +++ b/client/app/scripts/utils/web-api-utils.js @@ -214,16 +214,16 @@ export function deletePipe(pipeId) { } export function getPipeStatus(pipeId) { - const url = `/api/pipe/${encodeURIComponent(pipeId)}`; + const url = `/api/pipe/${encodeURIComponent(pipeId)}/check`; reqwest({ method: 'GET', url: url, success: function(res) { - log('ERROR: expected responses: [400, 404]. Got:', res); + log('ERROR: expected responses: [200, 404]. Got:', res); }, error: function(err) { const status = { - 400: 'PIPE_ALIVE', + 200: 'PIPE_ALIVE', 404: 'PIPE_DELETED' }[err.status];