FriendsOfSymfony / FOSJsRoutingBundle

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

Routing dump does not include port for local dev #440

Closed lampelk closed 11 months ago

lampelk commented 2 years ago

When dumping routes on local dev:

fos:js-routing:dump --format=json --target=public/js/routes.json

The json output does not include port if the web server is running with a port (e.g. 8080):

{
  "base_url": "",
  "routes": {
    "app_home": {
      "tokens": [["text", "\/home"]],
      "defaults": [],
      "requirements": [],
      "hosttokens": [],
      "methods": [],
      "schemes": []
    }
  },
  "prefix": "",
  "host": "localhost",
  "port": "",
  "scheme": "http",
  "locale": ""
}

Expected result:

"port": 8080

I found this issue when trying to generate absolute URLs:

Routing.generate('app_home', /* your params */, true)

Result:

http://localhost/home

Expected result:

http://localhost:8080/home

Environment: php: 8.0.2 symfony: 6.0* friendsofsymfony/jsrouting-bundle: 3.1.1

Related (maybe?): #391

bobvandevijver commented 11 months ago

You can try setting the HTTP_HOST env var when generating the file to localhost:8080. Are you using the older fos-routing npm package, or the one bootstrapped with the bundle? Version doesn't matter, you should always set the HTTP_HOST when generating the file from the command line, or call a method on the Router instance. I created an MR to clarify this in the documentation.