Skip to content
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

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

Merged
merged 1 commit into from
Mar 4, 2024

Conversation

wilr
Copy link
Member

@wilr wilr commented Feb 19, 2024

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

  • The target branch is correct
  • All commits are relevant to the purpose of the PR (e.g. no debug statements, unrelated refactoring, or arbitrary linting)
    • Small amounts of additional linting are usually okay, but if it makes it hard to concentrate on the relevant changes, ask for the unrelated changes to be reverted, and submitted as a separate PR.
  • The commit messages follow our commit message guidelines
  • The PR follows our contribution guidelines
  • Code changes follow our coding conventions
  • This change is covered with tests (or tests aren't necessary for this change)
  • Any relevant User Help/Developer documentation is updated; for impactful changes, information is added to the changelog for the intended release
  • CI is green

@madmatt
Copy link
Member

madmatt commented Feb 20, 2024

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
Copy link
Member Author

wilr commented Feb 20, 2024

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

@madmatt
Copy link
Member

madmatt commented Feb 23, 2024

Oh okay I did miss that part, nice _b

@mandrew
Copy link
Contributor

mandrew commented Feb 27, 2024

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
Copy link
Member

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

  • open a new issue so that we have an issue to track. We track issues, not pull requests.
  • add some steps to test this change.
  • Tick all the checkboxes that are relevant - you may find there are things that the checkboxes will point out (e.g. for a bug fix 5 is not the correct branch to target)

Comment on lines +84 to +85
CoreKernel::DEV,
CoreKernel::TEST,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't make this change outside of a major release without breaking some peoples' workflows.
Depending on what the issue actually is that you're trying to resolve, there might be another way to tackle it - but if this does turn out to be the correct way to resolve this problem, the PR will need to target the 6 branch and have an associated PR for the CMS 6 changelog.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated now!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Can you please open a pull request to the 6 branch of developer docs repo to update the CMS 6 changelog (you may need to add a new file for it)?
Please also create an issue and link the two PRs to it so I can track this.

@wilr wilr changed the base branch from 5 to 6 February 29, 2024 00:02
@wilr
Copy link
Member Author

wilr commented Feb 29, 2024

@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
Copy link
Member

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
Copy link
Member

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

@wilr
Copy link
Member Author

wilr commented Mar 4, 2024

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
Copy link
Member

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

The only things that are automatically generated for changelogs are:

  • commit references
  • deleted or changes API signatures (classes, interfaces, methods, etc) in minor releases

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
Copy link
Member Author

wilr commented Mar 4, 2024

Done! Created at silverstripe/developer-docs#465

@GuySartorelli
Copy link
Member

Fantastic. Can you please also create an issue and link both PRs to it as per #11154 (comment)?

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

Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making this change

@GuySartorelli GuySartorelli merged commit f4cbe92 into silverstripe:6 Mar 4, 2024
15 checks passed
@wilr wilr deleted the pr/url-middleware-local branch June 19, 2024 04:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants