(defn get-proxy-uri
"Parse the proxied uri forwarded by the ions api-gateway data"
[req]
(try
(let [path (-> req :datomic.ion.edn.api-gateway/json (json/read-str :key-fn keyword) :pathParameters :proxy)]
(str "/" path))
(catch Exception e nil)))
(defn wrap-proxy-uri
"Look in the proxied api-gateway data and re-assign the URI for routing purposes.
The API is likely configured with some resources and custom url. This middleware changes something like this
:uri stage-route/proxy-resource/one/two/three
to
:uri /one/two/three"
[handler]
(fn [request]
(if-let [proxy-uri (get-proxy-uri request)]
(handler (assoc request :uri proxy-uri))
(handler request))))
(defn wrap-middleware
[handler & [formats]]
(-> handler
; rejig the proxied uri
wrap-proxy-uri
))
(def web-handler (wrap-middleware (bidi.routes/make-handler routes)))
(def web-router (apigw/ionize web-handler))
Created
January 18, 2019 02:53
-
-
Save joshkh/9feef8b1912064c300b82356c96f490f to your computer and use it in GitHub Desktop.
blog-API-Gateway-Routing
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment