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

Add multi application support by adding expose groups #405

Open
alexander-schranz opened this issue May 1, 2021 · 3 comments
Open

Add multi application support by adding expose groups #405

alexander-schranz opened this issue May 1, 2021 · 3 comments

Comments

@alexander-schranz
Copy link

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?

@TheCelavi
Copy link

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.

@Tofandel
Copy link
Contributor

Tofandel commented Mar 18, 2022

This is such a requested feature, I have seen at least 5 issues about it, there has been forgotten PR #108

For laravel we have ziggy which has this feature as well as reverse route matching (eg: Router.unresolve(url) => gives you name and params)

We really need this for symfony

@raziel057
Copy link

Hi, the following #409 is also related

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

4 participants