Is it possible to do multi host with reitit-routes?
matheusfrancisco opened this issue · comments
I did found on the documentation anything about do a multiple host routes.
I would like to do a set of routes to when I hit api.xpto.com
it will redirect to be available some set of routes, and when I hit api2.xpto.com
it will be available another set of routes.
Currently, I have an application running in production with pedestal routes, so I was switching to reitit, but I miss this feature, if is something you guys would like to have or any suggestion I'm willing to open a pull request or something.
(ns myapp.service
(:require [io.pedestal.http.route :as route]))
(def application-routes
(route/expand-routes
#{{:host "example.com" :scheme :https}
["/user" :get user-search-form]
["/user/:user-id" :get view-user :constraints {:user-id #"[0-9]+"}]
,,,
}))
There is nothing built-in, but you can build this easily on top of reitit. e.g.
- create a middleware that reads
:host
and:schema
keys from route data. see parameter coercion middleware as example, e.g. either needs to needs to be set for the middleware to mount into to the route - mount the middleware to top-level
- attach data to route tree, at any level, e.g.
[["" {:host "example.com"} ...]
["/all-hosts"
["/trade" {:host "trade.com"} ...]
["/api"
["/admin" {:host "admin.com" :scheme :https} ...]
["/public" {:host "public.com"} ...]]]]
it might not be a use case for an example here in reitit but I will put my repo here https://github.com/matheusfrancisco/multihost-reitit-pedestal with the interceptor that work for simple case, than I will do a complex case and migrate the moclojer https://github.com/moclojer/moclojer for reitit
thanks for your support @ikitommi if you want you can close this issue