FriendsOfSymfony / FOSJsRoutingBundle

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

Generating absolute URL set host=localhost #357

Closed florianajir closed 5 years ago

florianajir commented 5 years ago

When I generate an url with absolute parameter = true from fosJsRoutingBundle the domain is not the good one; as classic symfony Router is able to produce.

eg:

let myUrl = Router.generate('en__RG__look_view', {'slug': 'test'}, true);
console.log(myUrl); // http://localhost/en/look/view/test
//should produce: https://sub.domain.tld/en/look/view/test
{% set myUrl = url('look_view', {'slug': 'test'}) %}
{{ dump(myUrl) }} {# https://sub.domain.tld/en/look/view/test #}

Maybe I missed something in configuration ?

Note: My web server is php-fpm behind an nginx reverse proxy.

stof commented 5 years ago

how are you initializing the router ? With the controller or with a dumped file ?

florianajir commented 5 years ago

how are you initializing the router ? With the controller or with a dumped file ?

with a dumped file generated on build time directly on the hosted server with this command: fos:js-routing:dump --format=json --target=assets/routes.json

But when I look in the file routes.json all the routes are describe with relative url:

{
  "base_url": "",
  "routes": {
     "en__RG__look_view": {
      "tokens": [
        [
          "variable",
          "\/",
          "[^\/]++",
          "slug"
        ],
        [
          "text",
          "\/en\/look\/view"
        ]
      ],
      "defaults": [],
      "requirements": [],
      "hosttokens": [],
      "methods": [],
      "schemes": []
    }
  }
}
florianajir commented 5 years ago

Problem solved I found the solution in the doc sorry I misread a part about configuring the router in command context (I tried previously but forget to regenerate the file after)

https://symfony.com/doc/current/console/request_context.html#configuring-the-request-context-globally

phtmgt commented 3 years ago

Any more specific hint about how to solve this? I have no idea how to fix the generate command.