-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Shorten and simplify path to CORS proxy (#2063)
## Motivation for the change, related issues The CORS proxy URL is long and requires the user to remember a specific PHP file path. ``` https://wordpress-playground-cors-proxy.net/cors-proxy.php ``` Let's shorten the URL and let people forget the PHP file name. With this PR, `https://wordpress-playground-cors-proxy.net/cors-proxy.php?https://example.com/` can be replaced with `https://wordpress-playground-cors-proxy.net/?https://example.com/` or `https://wordpress-playground-cors-proxy.net/https://example.com/` ## Implementation details Instead of trying to derive the target URL by removing `$_SERVER['SCRIPT_NAME']` from `$_SERVER['REQUEST_URI']`, we switch to taking the target URL from `$_SERVER['PATH_INFO']` or `$_SERVER['QUERY_STRING']`. In addition, we take advantage of WP Cloud's default script path and have that script define PATH_INFO if it doesn't exist. It shouldn't exist because WP Cloud isn't configured to provide path info today. (`$_SERVER['PATH_INFO']` === `/additional/info` when `$_SERVER['REQUEST_URI']` === '/path-to-script.php/additional/info'). ## Testing Instructions (or ideally a Blueprint) - Run unit tests from php-cors-proxy dir with `sh test.sh` - Run CORS proxy deploy workflow and test manually with proxy site. The following proxy URLs should all work: - https://wordpress-playground-cors-proxy.net/cors-proxy.php?https://wordpress.org/ - https://wordpress-playground-cors-proxy.net/?https://wordpress.org/ - https://wordpress-playground-cors-proxy.net/https://wordpress.org/
- Loading branch information
1 parent
518c2c2
commit d22c728
Showing
5 changed files
with
64 additions
and
19 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
packages/playground/php-cors-proxy-deployment/__wp__/index.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
if ( | ||
empty( $_SERVER['PATH_INFO'] ) && | ||
!str_starts_with($_SERVER['REQUEST_URI'], '/?') | ||
) { | ||
// Allow proxied URL to be provided via request URI, | ||
// even though WP cloud servers don't provided PATH_INFO. | ||
$_SERVER['PATH_INFO'] = $_SERVER['REQUEST_URI']; | ||
} | ||
require __DIR__ . '/../cors-proxy.php'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters