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

wp-now: add wp-admin redirection with trailing slash #60

Merged
merged 4 commits into from
Jun 2, 2023

Conversation

sejas
Copy link
Collaborator

@sejas sejas commented Jun 2, 2023

What?

It adds a redirection to /wp-admin to add the trailing slash /wp-admin/ so core loads the correct links in the sidebar.

Why?

How?

I created a middleware to add trailing slash given a path.

Testing Instructions

  • Run npx nx build wp-now
  • node dist/packages/wp-now/main.js start
  • Go to http://127.0.0.1:8881/wp-admin (without the last slash)
  • Observe you are redirected to http://127.0.0.1:8881/wp-admin/ and the sidebar menu has the correct links.

@@ -33,6 +33,16 @@ const requestBodyToString = async (req) =>
});
});

function addTrailingSlash(path) {
return (req, res, next) => {
if (req.url === path) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Will that work if the URL is /wp-admin?a=b?

Copy link
Member

Choose a reason for hiding this comment

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

I tested and it does not.

Maybe addTrailingSlash should be a standalone function with tests, and then we should have some other function for this middleware.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  • Now it supports get parameters /wp-admin?a=b
  • I moved the function to a new file, and included tests.

@sejas sejas requested review from adamziel and danielbachhuber June 2, 2023 14:28
Copy link
Member

@danielbachhuber danielbachhuber left a comment

Choose a reason for hiding this comment

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

Seems to work well! Thanks for adding tests 😊

@sejas sejas merged commit 4a0ea12 into trunk Jun 2, 2023
@sejas sejas deleted the update/wp-now-wp-admin-trailing-slash-redirection branch June 2, 2023 20:16
johnhooks pushed a commit to johnhooks/playground-tools that referenced this pull request Oct 11, 2024
Document the public and private APIs of all the packages in this repository.

This commit is polluted with code refactoring since many ideas stood out as overly complex while writing the docs. There isn't much value in separating them out at this point so they're here.

Follow-up work:

* Iterate on the docs, fix typos, gather more feedback, reword confusing fragments.
* Generate a proper reference doc in a markdown format. It should include the top-level module documentation, function documentation, and the classes + their methods. I'm not sure which tool can handle that correctly.
* Add the missing `wordpress-wasm` module documentation
* Fill-in any remaining blanks
johnhooks pushed a commit to johnhooks/playground-tools that referenced this pull request Oct 11, 2024
This PR populates /docs with a step-by-step documentation connecting the priors documentation efforts shipped in:

* API Reference documentation WordPress#63
* Migrate the project to TypeScript WordPress#61
* Add developer documentation  WordPress#60
* Monorepo WordPress#57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Redirect /wp-admin to /wp-admin/ as not to break the admin navigation menu
3 participants