-
Notifications
You must be signed in to change notification settings - Fork 86
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
Changes from all commits
67ff142
e98835d
743a363
c6171d1
01e0120
6118aff
e9809a6
2255b7f
a9cb06e
f9c3930
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -250,14 +250,14 @@ async function runIndexMode( php: PHP, { documentRoot, projectPath }: WPNowOptio | |
|
|
||
| async function runWpContentMode( | ||
| php: PHP, | ||
| { documentRoot, wordPressVersion, wpContentPath, projectPath, absoluteUrl }: WPNowOptions | ||
| { documentRoot, wordPressVersion, wpContentPath, projectPath }: WPNowOptions | ||
| ) { | ||
| const wordPressPath = path.join( getWordpressVersionsPath(), wordPressVersion ); | ||
| await php.mount( | ||
| wordPressPath, | ||
| createNodeFsMountHandler( documentRoot ) as unknown as MountHandler | ||
| ); | ||
| await initWordPress( php, wordPressVersion, documentRoot, absoluteUrl ); | ||
| await initWordPress( php, wordPressVersion, documentRoot ); | ||
| fs.ensureDirSync( wpContentPath ); | ||
|
|
||
| await php.mount( | ||
|
|
@@ -280,29 +280,25 @@ async function runWordPressDevelopMode( | |
| } ); | ||
| } | ||
|
|
||
| async function runWordPressMode( | ||
| php: PHP, | ||
| { documentRoot, projectPath, absoluteUrl }: WPNowOptions | ||
| ) { | ||
| async function runWordPressMode( php: PHP, { documentRoot, projectPath }: WPNowOptions ) { | ||
| php.mkdir( documentRoot ); | ||
| await php.mount( | ||
| documentRoot, | ||
| createNodeFsMountHandler( projectPath ) as unknown as MountHandler | ||
| ); | ||
|
|
||
| await initWordPress( php, 'user-provided', documentRoot, absoluteUrl ); | ||
| await initWordPress( php, 'user-provided', documentRoot ); | ||
| } | ||
|
|
||
| async function runPluginOrThemeMode( | ||
| php: PHP, | ||
| { wordPressVersion, documentRoot, projectPath, wpContentPath, absoluteUrl, mode }: WPNowOptions | ||
| { wordPressVersion, documentRoot, projectPath, wpContentPath, mode }: WPNowOptions | ||
| ) { | ||
| const wordPressPath = path.join( getWordpressVersionsPath(), wordPressVersion ); | ||
| await php.mount( | ||
| wordPressPath, | ||
| createNodeFsMountHandler( documentRoot ) as unknown as MountHandler | ||
| ); | ||
| await initWordPress( php, wordPressVersion, documentRoot, absoluteUrl ); | ||
| await initWordPress( php, wordPressVersion, documentRoot ); | ||
|
|
||
| fs.ensureDirSync( wpContentPath ); | ||
| fs.copySync( | ||
|
|
@@ -344,14 +340,14 @@ async function runPluginOrThemeMode( | |
|
|
||
| async function runWpPlaygroundMode( | ||
| php: PHP, | ||
| { documentRoot, wordPressVersion, wpContentPath, absoluteUrl }: WPNowOptions | ||
| { documentRoot, wordPressVersion, wpContentPath }: WPNowOptions | ||
| ) { | ||
| const wordPressPath = path.join( getWordpressVersionsPath(), wordPressVersion ); | ||
| await php.mount( | ||
| wordPressPath, | ||
| createNodeFsMountHandler( documentRoot ) as unknown as MountHandler | ||
| ); | ||
| await initWordPress( php, wordPressVersion, documentRoot, absoluteUrl ); | ||
| await initWordPress( php, wordPressVersion, documentRoot ); | ||
|
|
||
| fs.ensureDirSync( wpContentPath ); | ||
| fs.copySync( | ||
|
|
@@ -418,12 +414,7 @@ async function login( php: PHP, options: WPNowOptions = {} ) { | |
| * @param vfsDocumentRoot | ||
| * @param siteUrl | ||
| */ | ||
| async function initWordPress( | ||
| php: PHP, | ||
| wordPressVersion: string, | ||
| vfsDocumentRoot: string, | ||
| siteUrl: string | ||
| ) { | ||
| async function initWordPress( php: PHP, wordPressVersion: string, vfsDocumentRoot: string ) { | ||
| let initializeDefaultDatabase = false; | ||
| if ( ! php.fileExists( `${ vfsDocumentRoot }/wp-config.php` ) ) { | ||
| php.writeFile( | ||
|
|
@@ -433,10 +424,7 @@ async function initWordPress( | |
| initializeDefaultDatabase = true; | ||
| } | ||
|
|
||
| const wpConfigConsts = { | ||
| WP_HOME: siteUrl, | ||
| WP_SITEURL: siteUrl, | ||
| }; | ||
| const wpConfigConsts = {}; | ||
|
|
||
| if ( wordPressVersion !== 'user-provided' ) { | ||
| wpConfigConsts[ 'WP_AUTO_UPDATE_CORE' ] = wordPressVersion === 'latest'; | ||
|
|
@@ -471,6 +459,36 @@ export function getThemeTemplate( projectPath: string ) { | |
| async function mountInternalMuPlugins( php: PHP ) { | ||
| php.mkdir( PLAYGROUND_INTERNAL_MU_PLUGINS_FOLDER ); | ||
|
|
||
| php.writeFile( | ||
| path.posix.join( PLAYGROUND_INTERNAL_MU_PLUGINS_FOLDER, '0-https-for-reverse-proxy.php' ), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good on remembering to use POSIX paths 👍 |
||
| `<?php | ||
| // See https://developer.wordpress.org/advanced-administration/security/https/#using-a-reverse-proxy | ||
| if( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && strpos( $_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false ){ | ||
| $_SERVER['HTTPS'] = 'on'; | ||
| } | ||
| ` | ||
| ); | ||
|
|
||
| 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; | ||
| } | ||
| }); | ||
| ` | ||
| ); | ||
|
Comment on lines
+472
to
+490
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On 01e0120 I explored a solution having a function 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To recap, is the issue here that
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fredrikekelund correct. It seems it also doesn't handle non-ssl |
||
|
|
||
| php.writeFile( | ||
| path.posix.join( PLAYGROUND_INTERNAL_MU_PLUGINS_FOLDER, '0-allowed-redirect-hosts.php' ), | ||
| `<?php | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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
siteurlandhomenow..? 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.
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.
This is correct. Studio calls
wp-admin/install.phpto 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#L93There 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.
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.