Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to do multi host with reitit-routes? #660

Closed
matheusfrancisco opened this issue Feb 3, 2024 · 2 comments
Closed

Is it possible to do multi host with reitit-routes? #660

matheusfrancisco opened this issue Feb 3, 2024 · 2 comments

Comments

@matheusfrancisco
Copy link

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]+"}]
      ,,,
      }))
@ikitommi
Copy link
Member

ikitommi commented Feb 4, 2024

There is nothing built-in, but you can build this easily on top of reitit. e.g.

  1. 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
  2. mount the middleware to top-level
  3. 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"} ...]]]]

@matheusfrancisco
Copy link
Author

matheusfrancisco commented Feb 4, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants