Skip to content

[FrameworkBundle] Allow configuring the default base URI with a DSN #36651

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

Merged
merged 1 commit into from
May 4, 2020

Conversation

nicolas-grekas
Copy link
Member

Q A
Branch? master
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fixes #35121, replaces #35580, partially reverts #35281
License MIT
Doc PR -

Instead of defining 3-4 parameters, this PR enables using a single DSN to configure the default URL context (for commands mainly):

framework:
	router:
		base_uri: 'https://my.host:8443/base-path/'

When using parameters directly, one can now set the same absolute URI in the router.request_context.base_url parameter, this will provide the same benefit.

@Nyholm
Copy link
Member

Nyholm commented May 3, 2020

I like this PR. Im 👍 on the implementation.

I just have the one question about naming things =)

@fabpot
Copy link
Member

fabpot commented May 4, 2020

Thank you @nicolas-grekas.

@fabpot fabpot merged commit e9be741 into symfony:master May 4, 2020
@nicolas-grekas nicolas-grekas deleted the req-ctx branch May 4, 2020 07:51
@nicolas-grekas nicolas-grekas modified the milestones: next, 5.1 May 4, 2020
fabpot added a commit that referenced this pull request May 5, 2020
…r assets (nicolas-grekas)

This PR was merged into the 5.1-dev branch.

Discussion
----------

[FrameworkBundle] use the router context by default for assets

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Follows #36651 and #21027

This means assets are going to be configured automatically most of the time. The only case where `asset.request_context.base_path` is useful is when the webserver still keeps a `/index.php/` in URLs. (I'm not sure if the doc should tell ppl to use the parameter, or if we should tell ppl to improve the config of their server...)

Commits
-------

1ac5f68 [FrameworkBundle] use the router context by default for assets
@fabpot fabpot mentioned this pull request May 5, 2020
nicolas-grekas added a commit that referenced this pull request Apr 19, 2022
…g slash (Tobion)

This PR was merged into the 5.4 branch.

Discussion
----------

[Routing] fix router base url when default uri has trailing slash

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       |
| License       | MIT
| Doc PR        |

When the router default uri (feature #36651) has a trailing slash, the generated URLs are wrong. E.g.

```yaml
framework:
    router:
        default_uri: 'https://example.org/' # this is equivalent URI to 'https://example.org'
 ```

Generating any absolute URL given this base path currently resulted in double slashes, e.g. `https://example.org//mypage`
because the base url is set to `/` and the path info defaults to `/` as well. This is not correct and will result in a 404.

The most consistent fix with the rest of symfony is to always rtrim the trailing slashes from the base url.
This is already done in the HttpFoundation Request class see https://github.com/symfony/symfony/blob/674ad07a684fe1274ae49d9f4b6294ede3b47b92/src/Symfony/Component/HttpFoundation/Request.php#L849
So I think it makes sense to enforce this also on the requestcontext so it is also the case when it does not go through the fromRequest but via fromUri in the CLI.

Commits
-------

07136a9 [Routing] fix router base url when default uri has trailing slash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FrameworkBundle] URL for setting the request context
7 participants