From 4c3a5986d6e70c4cdd56744ccf9ad5d0e8f0fd0f Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Mon, 11 Apr 2022 16:23:45 +0200 Subject: [PATCH] Redirect /job to / and /job/:job/build to /job/:job replaces #81 --- lib/builder_web.ml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/builder_web.ml b/lib/builder_web.ml index 56523ab..e277c5d 100644 --- a/lib/builder_web.ml +++ b/lib/builder_web.ml @@ -476,11 +476,23 @@ let add_routes datadir configdir = >>= fun () -> Dream.respond "" |> Lwt_result.ok in + let redirect_parent req = + let path = Dream.target req in + let parent = + String.split_on_char '/' |> + List.rev |> List.tl |> List.rev |> + String.concat "/" + in + Dream.redirect ~status:`Temporary_Redirect req (parent ^ "/") + in + let w f req = or_error_response (f req) in Dream.router [ Dream.get "/" (w builds); + Dream.get "/job" (w redirect_parent); Dream.get "/job/:job/" (w job); + Dream.get "/job/:job/build" (w redirect_parent); Dream.get "/job/:job/failed/" (w job_with_failed); Dream.get "/job/:job/build/latest/**" (w redirect_latest); Dream.get "/job/:job/build/:build/" (w job_build);