-
Notifications
You must be signed in to change notification settings - Fork 53
Add tunneling support #936
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
Conversation
| php.writeFile( | ||
| path.posix.join( PLAYGROUND_INTERNAL_MU_PLUGINS_FOLDER, '0-redirect-to-siteurl-constant.php' ), | ||
| `<?php | ||
| // See https://core.trac.wordpress.org/ticket/33821#comment:10 | ||
| add_action( 'init', function() { | ||
| if ( ! defined( 'WP_SITEURL' ) ) { | ||
| return; | ||
| } | ||
| $current_host = $_SERVER['HTTP_HOST'] ?? ''; | ||
| if ( preg_match( '/^localhost:\\d+$/', $current_host ) ) { | ||
| $requested_uri = $_SERVER['REQUEST_URI'] ?? '/'; | ||
| wp_redirect( rtrim( WP_SITEURL, '/' ) . $requested_uri, 302 ); | ||
| exit; | ||
| } | ||
| }); | ||
| ` | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On 01e0120 I explored a solution having a function geWpConfigConstants that exposed wp-config.php constants to Studio to display the correct links in wp-admin and open site.
After discussing it with @wojtekn , we decided to simplify the logic and relay in WordPress default redirect. Due to this issue https://core.trac.wordpress.org/ticket/33821#comment:10 the redirect doesn't work out of the box and we need this mu plugin.
The wp-admin link redirects correctly to the ngrok url defined in WP_SITEURL, but it doesn't perform the autologin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To recap, is the issue here that redirect_canonical doesn't work properly when we request a URL that includes a port number?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fredrikekelund correct. It seems it also doesn't handle non-ssl http://localhost:8888/ redirect to https://my-tunnel.com/ well. It would make sense to dedicate some time later to check what we could do to rely on the core redirect_canonical.
| const wpConfigConsts = { | ||
| WP_HOME: siteUrl, | ||
| WP_SITEURL: siteUrl, | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing this constants can uncover some issues in sites where the option siteurl and home point to a different URL.
When starting those sites WordPress will redirect to the URL saved in the database which will lead to a "non-response" page.
We can fix this behaviour in a different PR where we update those variables in database when we create a site with an existing SQLite database that already contains a siteurl with a different port.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added one issue I've uncovered: #939
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do we actually define siteurl and home now..? Are those options just implied in the installation process?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing this constants can uncover some issues in sites where the option siteurl and home point to a different URL.
Isn't that normal behavior for WordPress, though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do we actually define siteurl and home now..? Are those options just implied in the installation process?
This is correct. Studio calls wp-admin/install.php to install WordPress, which internally guesses the correct site url and saves it as option in the database. It happens in https://github.com/WordPress/WordPress/blob/c5cc9402b42939fd6a1370a7a463748ac9a2f595/wp-admin/includes/upgrade.php#L93
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't that normal behavior for WordPress, though?
It is, and it should be done that way in the first place. Removing that now can uncover some issues, though. With those constants being set by Studio in a brute force way, it was masking flows in which the siteurl/home ended up being incorrect. One of those is an issue I linked above.
fredrikekelund
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍 I tested this with Jurassic Tube and it worked great.
I left a couple of questions that would be good to have answers for, but they shouldn't block merging.
| php.mkdir( PLAYGROUND_INTERNAL_MU_PLUGINS_FOLDER ); | ||
|
|
||
| php.writeFile( | ||
| path.posix.join( PLAYGROUND_INTERNAL_MU_PLUGINS_FOLDER, '0-https-for-reverse-proxy.php' ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good on remembering to use POSIX paths 👍
| php.writeFile( | ||
| path.posix.join( PLAYGROUND_INTERNAL_MU_PLUGINS_FOLDER, '0-redirect-to-siteurl-constant.php' ), | ||
| `<?php | ||
| // See https://core.trac.wordpress.org/ticket/33821#comment:10 | ||
| add_action( 'init', function() { | ||
| if ( ! defined( 'WP_SITEURL' ) ) { | ||
| return; | ||
| } | ||
| $current_host = $_SERVER['HTTP_HOST'] ?? ''; | ||
| if ( preg_match( '/^localhost:\\d+$/', $current_host ) ) { | ||
| $requested_uri = $_SERVER['REQUEST_URI'] ?? '/'; | ||
| wp_redirect( rtrim( WP_SITEURL, '/' ) . $requested_uri, 302 ); | ||
| exit; | ||
| } | ||
| }); | ||
| ` | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To recap, is the issue here that redirect_canonical doesn't work properly when we request a URL that includes a port number?
| const wpConfigConsts = { | ||
| WP_HOME: siteUrl, | ||
| WP_SITEURL: siteUrl, | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do we actually define siteurl and home now..? Are those options just implied in the installation process?
Related issues
Proposed Changes
WP_SITEURLandWP_HOMEconstants in wp-config.phpKudos to @wojtekn for suggesting this approach p1739469267935719-slack-C06DRMD6VPZ
Testing Instructions
npm startWP_SITEURLandWP_HOMEconstants at the top of the filehttp://whatever.localhost:8881or runngrok http 8881and use the url returned by ngrok. 8881 is the port set by Studio and you can see it in the Settings tab.Note
The autologin doesn't work if you are using Ngrok, and we don't plan to fix it in this PR.
studio-simple-solution-wp-config-constants.mp4
Pre-merge Checklist