FriendsOfSymfony / FOSJsRoutingBundle

A pretty nice way to expose your Symfony routing to client applications.
1.48k stars 261 forks source link

expose domains #346

Closed tugrul closed 5 years ago

tugrul commented 5 years ago

We can expose routes for only one domain in actual functionality.

/**
 * @Route("/a-page",
 *     options = { "expose" = true },
 *     name = "my_route_to_expose_with_defaults",
 * )
 */

Able to expose routes to different domains like following.

/**
 * @Route("/a-page",
 *     options = { "expose" = "blog" },
 *     name = "my_route_to_expose_blog",
 * )
 */

/**
 * @Route("/a-secret-page",
 *     options = { "expose" = "admin" },
 *     name = "my_route_to_expose_admin",
 * )
 */

Then we can expose routes by different contexts like following.

<script src="{{ path('fos_js_routing_js', {"callback": "fos.Router.setData", "domain": "blog"}) }}"></script>
<script src="{{ path('fos_js_routing_js', {"callback": "fos.Router.setData", "domain": "admin"}) }}"></script>

also

$ php bin/console fos:js-routing:dump --domain=blog
<script src="/js/fos_js_routes_blog.js"></script>
$ php bin/console fos:js-routing:dump --domain=admin
<script src="/js/fos_js_routes_admin.js"></script>

{ "expose" = true } able to mean {"expose" = "default"} or {"expose" = "main"} to backward compatibility

Also merge all of domains' routes into single dump if we don't provide domain name like following.

$ php bin/console fos:js-routing:dump
<script src="/js/fos_js_routes.js"></script>

Also we can combine domain names

$ php bin/console fos:js-routing:dump --domain=admin,blog
<script src="{{ path('fos_js_routing_js', {"callback": "fos.Router.setData", "domain": ["blog", admin]}) }}"></script>
tobias-93 commented 5 years ago

Closed via #347