Add multi application support by adding expose groups
alexander-schranz opened this issue · comments
Current Situation
Currently FosJSRoutingBundle can be configured in the following ways to output the routes. First one is by adding expose: true
parameter to specific routes e.g.:
my_route_to_expose:
pattern: /foo/{id}/bar
defaults: { _controller: AppBundle:Default:index }
options:
expose: true
The second one is by configuring specifc routes to be outputed:
fos_js_routing:
routes_to_expose: [ route_1, route_2, ... ]
And then you add the following to your twig:
<script src="{{ asset('bundles/fosjsrouting/js/router.js') }}"></script>
<script src="{{ path('fos_js_routing_js', { callback: 'fos.Router.setData' }) }}"></script>
This works great.
Issue
Now I came to the issue. Sometimes there is the case that you have additional application with different routes. So you want to have a second endpoint to provide them as you maybe don't want that routes for application a can be seen by users from application b.
Proposal Add expode_group attribute
my_route_to_expose:
pattern: /foo/{id}/bar
defaults: { _controller: AppBundle:Default:index }
options:
expose_group: admin
The second one is by configuring specifc routes to be outputed:
fos_js_routing:
routes_to_expose_group:
admin: [ route_1, route_2, ... ]
As you want maybe have the routes behind a firewall best would be that the application itself defines to route to the js routing.
app.routing_js.admin:
pattern: /my-app/routes.js
defaults:
_controller: FOSJ:Default:index
group: admin
something like this should then also work:
app.routing_js.admin:
pattern: /my-app/{group}/routes.js
defaults:
_controller: FOSJ:Default:index
The controller provided by the bundle get then $group
parameter and only returns the route for that specific group.
What do you think about this idea?
Actually, we have similar issue as well. We have two set of APIs exposed by server application. Two consumers are using those two sets of routes. We would benefit as well if we could export different groups of routes as well, compiled javascript with routes would be smaller.
Hi, the following #409 is also related