Hello!
I have a Phoenix application with a bunch of routes, looking like this:
scope "/", MyServiceWeb do
pipe_through :api
get "/foo", FooController, :foo
get "/bar", BarController, :bar
[ many more ]
end
I am tasked with adding versioning to this API, for which we went with a path prefix approach, but the old endpoints have to be kept to avoid having to change all other services that use this API.
Having changed the code structure to reflect this, I updated the router to look like this:
scope "/", MyServiceWeb.V1 do # Notice the V1 here
pipe_through :api
get "/foo", FooController, :foo
get "/bar", BarController, :bar
[ many more ]
end
scope "/v1", MyServiceWeb.V1 do
pipe_through :api
get "/foo", FooController, :foo
get "/bar", BarController, :bar
[ many more ]
end
This works but there’s the issue of duplication that I would like to avoid, if at all possible. I would like to share the route definitions between the two scopes, something like this:
scope ["/", "/v1"], MyServiceWeb.V1 do
Is this doable someway?