silverstripe / silverstripe-framework

Silverstripe Framework, the MVC framework that powers Silverstripe CMS
https://www.silverstripe.org
BSD 3-Clause "New" or "Revised" License
719 stars 820 forks source link

fix: by default CanonicalURLMiddleware should run in all environments #11154

Closed wilr closed 4 months ago

wilr commented 4 months ago

Description

Currently CanonicalURLMiddleware only runs in production, this leads to the classic example of 'It works on mine(tm)' but more dangerously 'It works on the test site (tm)'. Out of the box, we should have as close to production behaviour as possible.

While the benefits don't apply to dev / test environments the side effects of the behaviour definitely apply.

cc @madmatt

Manual testing steps

Issues

Pull request checklist

madmatt commented 4 months ago

Pushing this to dev might be a bit over the top (though having TLS on localhost is possible and is much more common in these days of Docker etc), but I definitely think it should apply to test and live because these environments should always be considered identical (in as many ways as possible).

wilr commented 4 months ago

Forcing SSL is still not enabled by default in dev. You'll need to opt in via Injector as you would currently.

madmatt commented 4 months ago

Oh okay I did miss that part, nice _b

mandrew commented 4 months ago

I got caught out on this yesterday :( however it's a big change and might be best to wait to 6? Also any documentation that points to CanonicalURLMiddleware working only in live mode will need to be changed

GuySartorelli commented 4 months ago

Please use the pull request template, which I have added back for you. The following need to be done:

wilr commented 4 months ago

@GuySartorelli updated to v6 now. If you want to see the issue in place have a fetch('page.url') somewhere on your page. You'll find this works on development environment, once you're in production this will return a 301 redirect to page.url/

GuySartorelli commented 4 months ago

You'll find this works on development environment, once you're in production this will return a 301 redirect to page.url/

I assume you mean this happens from a fresh installation - there are multiple items of configuration that could change this result, including setting the enabled environments via injector config.

GuySartorelli commented 4 months ago

I'll be happy to merge this once there is a matching PR to the silverstripe/developer-docs as per https://github.com/silverstripe/silverstripe-framework/pull/11154#discussion_r1506847367

wilr commented 4 months ago

I'll be happy to merge this once there is a matching PR to the silverstripe/developer-docs as per #11154 (comment)

Won't it just be automated generated as it's a bug fix?

GuySartorelli commented 4 months ago

Won't it just be automated generated as it's a bug fix?

The only things that are automatically generated for changelogs are:

Changes to default values in protected member properties are not automatically documented in changelogs - and the potential ramifications and how to change those settings yourself are definitely not automatically documented.

wilr commented 4 months ago

Done! Created at https://github.com/silverstripe/developer-docs/pull/465

GuySartorelli commented 4 months ago

Fantastic. Can you please also create an issue and link both PRs to it as per https://github.com/silverstripe/silverstripe-framework/pull/11154#issuecomment-1970058062?

It's harder to track PRs than issues, especially when there are multiple related PRs.