-
Notifications
You must be signed in to change notification settings - Fork 448
Configure saved-site export API deployment #4220
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
Merged
+258
−32
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
6e15dd7
Support filtered saved-site ZIP exports
ashfame 8e7f9b5
Declare ignore dependency at workspace root
ashfame 32f1b4e
Strengthen OPFS export filter coverage
ashfame 2a072fe
remove assertions that were about test fixture
ashfame d6a2309
fix type
ashfame 314fd8f
Add lightweight saved-site export API
ashfame 78a4eda
don't move the type trying to prevent what seems like a circular depe…
ashfame 74b46d8
Update packages/playground/client/src/index.ts
ashfame 111a5c7
show short explanation on api.html if loaded directly (#4233)
ashfame 140d1ad
Improve saved-site export API tests
ashfame acd1cd2
Merge remote-tracking branch 'refs/remotes/pr4219-trunk-current' into…
ashfame 6ddc1e7
Address Playground API review feedback
ashfame d723e10
Derive API endpoint label from path
ashfame 932bf6e
simplify docs
ashfame a6be5cd
Document api.html manual chunk workaround
ashfame 27cc386
Configure saved-site export API deployment
ashfame File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,12 +1,12 @@ | ||
| Options +Multiviews | ||
| AddEncoding x-gzip .gz | ||
|
|
||
| <FilesMatch "index\.html"> | ||
| <FilesMatch "index\.html|api\.html"> | ||
| Header unset ETag | ||
| Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate" | ||
| </FilesMatch> | ||
| <FilesMatch "index\.js|blueprint-schema\.json|logger.php|wp-cli.phar|wordpress-importer.zip|php-code-snippet\.js"> | ||
| Header set Access-Control-Allow-Origin "*" | ||
| Header unset ETag | ||
| Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate" | ||
| </FilesMatch> | ||
| </FilesMatch> | ||
This file contains hidden or 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,24 @@ | ||
| <!doctype html> | ||
| <html> | ||
| <head> | ||
| <title>WordPress Playground API</title> | ||
| </head> | ||
| <body> | ||
| <p id="api-description" hidden> | ||
| WordPress Playground uses this page to export saved sites. It isn't | ||
| intended to be opened directly. | ||
| </p> | ||
| <script> | ||
| if (window.self === window.top) { | ||
| document.getElementById('api-description').hidden = false; | ||
| } | ||
| </script> | ||
| <script type="module"> | ||
| import { bootPlaygroundAPI } from './src/lib/boot-playground-api'; | ||
|
|
||
| if (window.self !== window.top) { | ||
| window.playgroundAPI = bootPlaygroundAPI(); | ||
| } | ||
| </script> | ||
| </body> | ||
| </html> |
35 changes: 35 additions & 0 deletions
35
packages/playground/website/src/lib/boot-playground-api.spec.ts
This file contains hidden or 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,35 @@ | ||
| import { bootPlaygroundAPI } from './boot-playground-api'; | ||
|
|
||
| const mocks = vi.hoisted(() => ({ | ||
| setAPIReady: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock('@php-wasm/universal', () => ({ | ||
| exposeAPI: vi.fn((api: object) => [ | ||
| mocks.setAPIReady, | ||
| vi.fn(), | ||
| { | ||
| ...api, | ||
| isConnected: vi.fn(async () => undefined), | ||
| isReady: vi.fn(async () => undefined), | ||
| }, | ||
| ]), | ||
| })); | ||
|
|
||
| vi.mock('./state/opfs/opfs-site-storage', () => ({ | ||
| opfsSiteStorage: undefined, | ||
| })); | ||
|
|
||
| describe('bootPlaygroundAPI', () => { | ||
| afterEach(() => { | ||
| vi.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('reports when OPFS site storage is unavailable', async () => { | ||
| const api = bootPlaygroundAPI(); | ||
|
|
||
| await expect(api.exportSavedSiteAsZip('my-site')).rejects.toThrow( | ||
| 'OPFS site storage is unavailable in this context.' | ||
| ); | ||
| }); | ||
| }); |
18 changes: 18 additions & 0 deletions
18
packages/playground/website/src/lib/boot-playground-api.ts
This file contains hidden or 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,18 @@ | ||
| import { exposeAPI } from '@php-wasm/universal'; | ||
| import type { PlaygroundAPIClient } from '@wp-playground/client'; | ||
| import { opfsSiteStorage } from './state/opfs/opfs-site-storage'; | ||
|
|
||
| export function bootPlaygroundAPI() { | ||
| const [setAPIReady, , api] = exposeAPI<PlaygroundAPIClient, unknown>({ | ||
| async exportSavedSiteAsZip(slug, options) { | ||
| if (!opfsSiteStorage) { | ||
| throw new Error( | ||
| 'OPFS site storage is unavailable in this context.' | ||
| ); | ||
| } | ||
| return await opfsSiteStorage.exportSavedSiteAsZip(slug, options); | ||
| }, | ||
| }); | ||
| setAPIReady(); | ||
| return api; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
As I understand it,
remote.htmlcan be added here for completeness. But it's not needed, since service worker has explicit behavior around not caching it. This is only relevant for a self-hoster wanting to use apache, but even then won't make a difference. So, I would rather not touch it for now.