Skip to content

Update .htaccess to serve correct CORS headers for /client/index.js #873

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

Closed
3 tasks done
adamziel opened this issue Dec 15, 2023 · 0 comments · Fixed by #989
Closed
3 tasks done

Update .htaccess to serve correct CORS headers for /client/index.js #873

adamziel opened this issue Dec 15, 2023 · 0 comments · Fixed by #989
Labels

Comments

@adamziel
Copy link
Collaborator

adamziel commented Dec 15, 2023

Description

#773 exposed the client library on Playground.wordpress.net:

https://playground.wordpress.net/client/index.js

That PR was accompanied by a .htaccess update to ensure the correct Access-Control-Allow-Origin header was set – otherwise the index.js file cannot be import()-ed in JavaScript.

Unfortunately, that update was lost in a force-push. I patched it ad-hoc on the server, but we should ship the correct setup out of the box.

Luckily, GitHub still keeps that code change here:

a6f685d

Let's restore it! Here's a copy of the changes just in case that commit gets garbage collected:

packages/playground/website/.htaccess

<FilesMatch "(client\/|blueprint-schema\.json)">
Header set Access-Control-Allow-Origin "*"
</FilesMatch>

packages/playground/website/project.json

-					"cat ./remote/.htaccess > ./wasm-wordpress-net/.htaccess"
+					"cat ./remote/.htaccess ./website/.htaccess > ./wasm-wordpress-net/.htaccess"

Also, let's make sure that proper cache busting is in place.

Done is:

  • The .htaccess file is shipped with the website build
  • The .htaccess file shipped with the website build ensures the browsers won't cache client.js once its contents change
  • The .htaccess file shipped with the website build ensures the correct Access-Control-Allow-Origin: * header is sent – but only for the client.js file
@seanmorris seanmorris self-assigned this Dec 22, 2023
adamziel added a commit that referenced this issue Jan 31, 2024
Adds a .htaccess file to playground.wordpress.net that does the following:

1. Prevents caching of the main index.html file. Otherwise the browser may
   try to load outdated JavaScript, CSS, and WASM assets and and up in a
   broken state.
2. Adds the Access-Control-Allow-Origin header for the blueprint-schema.json
   file and the hosted client.js library to enable `import()`-ing both.

 ## Testing instructions

None. I tested this in an Apache setup, then manually updated the production
.htaccess file, and it all worked as expected.

Related to #855
Closes #873
adamziel added a commit that referenced this issue Jan 31, 2024
…le importing the client.js library (#989)

Adds a .htaccess file to playground.wordpress.net that does the
following:

1. Prevents caching of the main index.html file. Otherwise the browser
may try to load outdated JavaScript, CSS, and WASM assets and and up in
a broken state.
2. Adds the Access-Control-Allow-Origin header for the
blueprint-schema.json file and the hosted client.js library to enable
`import()`-ing both.

## Testing instructions

None. I tested this in an Apache setup, then manually updated the
production .htaccess file, and it all worked as expected.

Related to #855
Closes #873
adamziel added a commit that referenced this issue Jan 31, 2024
Ensures the browsers won't cache client.js once its contents changes. The
`Cache-Control: no-cache` shipped here may perhaps be too restrictive, but
it's a good starting point that can be tweaked later.

Related to #873
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants