Requests resolved directly via the JS API (playground.request()) return error 404 if URL rewriting is required to resolve them. For example, playground.request({ url: '/glotpress/projects }); wouldn't get resolved as /index.php/glotpress/projects. This is because Playground simulates the required .htaccess rules in the service worker:
|
if (workerResponse.status === 404) { |
|
for (const url of rewriteWordPressUrl(unscopedUrl, scope!)) { |
|
rewrittenUrlString = url.toString(); |
|
workerResponse = await convertFetchEventToPHPRequest( |
|
await cloneFetchEvent(event, rewrittenUrlString) |
|
); |
|
if ( |
|
workerResponse.status !== 404 || |
|
workerResponse.headers.get('x-file-type') === 'static' |
|
) { |
|
break; |
|
} |
|
} |
|
} |
And only fetch() requests are affected. Instead, Playground should apply the following .htaccess rules in the request handler:
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Since PHPRequestHandler is generic and specific to @php-wasm, Playground should provide its own WordPress-specific handler, perhaps via the @wp-playground/wordpress package?
cc @akirk @bgrgicak
Requests resolved directly via the JS API (
playground.request()) return error 404 if URL rewriting is required to resolve them. For example,playground.request({ url: '/glotpress/projects });wouldn't get resolved as/index.php/glotpress/projects. This is because Playground simulates the required.htaccessrules in the service worker:wordpress-playground/packages/playground/remote/service-worker.ts
Lines 51 to 64 in 454fec3
And only
fetch()requests are affected. Instead, Playground should apply the following .htaccess rules in the request handler:Since
PHPRequestHandleris generic and specific to@php-wasm, Playground should provide its own WordPress-specific handler, perhaps via the@wp-playground/wordpresspackage?cc @akirk @bgrgicak