Skip to content

Commit

Permalink
Merge pull request #55 from oliyh/pr53
Browse files Browse the repository at this point in the history
Support trimming trailing slashes from base URL
  • Loading branch information
oliyh authored Jun 22, 2018
2 parents e457cbe + 61e66eb commit 6c1a3e6
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions cljs-http/src/martian/cljs_http.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
[cljs.core.async :refer [<!]]
[martian.core :as martian]
[martian.interceptors :as i]
[tripod.context :as tc])
[tripod.context :as tc]
[clojure.string :as str])
(:require-macros [cljs.core.async.macros :refer [go]]))

(defn- go-async [ctx]
Expand All @@ -24,12 +25,15 @@
(defn bootstrap [api-root concise-handlers & [opts]]
(martian/bootstrap api-root concise-handlers (merge {:interceptors default-interceptors} opts)))

(defn bootstrap-swagger [url & [{:keys [interceptors] :as params}]]
(defn bootstrap-swagger [url & [{:keys [interceptors trim-base-url?] :as params}]]
(go (let [swagger-definition (:body (<! (http/get url {:as :json})))
{:keys [scheme server-name server-port]} (http/parse-url url)
base-url (str (when-not (re-find #"^/" url)
(str (name scheme) "://" server-name (when server-port (str ":" server-port))))
(get swagger-definition :basePath ""))]
raw-base-url (str (when-not (re-find #"^/" url)
(str (name scheme) "://" server-name (when server-port (str ":" server-port))))
(get swagger-definition :basePath ""))
base-url (if trim-base-url?
(str/replace raw-base-url #"/$" "")
raw-base-url)]
(martian/bootstrap-swagger
base-url
swagger-definition
Expand Down

0 comments on commit 6c1a3e6

Please sign in to comment.