Skip to content

Commit 9a3a1e8

Browse files
committed
Website: Add .htaccess file
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
1 parent 7c7dce7 commit 9a3a1e8

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

packages/playground/website/.htaccess

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<FilesMatch "index\.html">
2+
Header unset ETag
3+
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
4+
</FilesMatch>
5+
<FilesMatch "(client\/|blueprint-schema\.json)">
6+
Header set Access-Control-Allow-Origin "*"
7+
</FilesMatch>

packages/playground/website/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"cp -r ./client ./wasm-wordpress-net/",
2020
"cp -r ./remote/* ./wasm-wordpress-net/",
2121
"cp -r ./website/* ./wasm-wordpress-net/",
22-
"cat ./remote/.htaccess > ./wasm-wordpress-net/.htaccess"
22+
"cat ./remote/.htaccess ./website/.htaccess > ./wasm-wordpress-net/.htaccess"
2323
],
2424
"cwd": "dist/packages/playground",
2525
"parallel": false

packages/playground/website/vite.config.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference types="vitest" />
22
import { defineConfig } from 'vite';
3-
import type { ViteDevServer } from 'vite';
3+
import type { Plugin, ViteDevServer } from 'vite';
44
import react from '@vitejs/plugin-react';
55
import { execSync } from 'node:child_process';
66
// eslint-disable-next-line @nx/enforce-module-boundaries
@@ -18,6 +18,8 @@ import {
1818
import virtualModule from '../vite-virtual-module';
1919
import { oAuthMiddleware } from './vite.oauth';
2020
import { fileURLToPath } from 'node:url';
21+
import { copyFileSync, existsSync } from 'node:fs';
22+
import { join } from 'node:path';
2123

2224
const proxy = {
2325
'^/plugin-proxy': {
@@ -34,6 +36,7 @@ try {
3436
buildVersion = (new Date().getTime() / 1000).toFixed(0);
3537
}
3638

39+
const path = (filename: string) => new URL(filename, import.meta.url).pathname;
3740
export default defineConfig(({ command, mode }) => {
3841
return {
3942
// Split traffic from this server on dev so that the iframe content and outer
@@ -92,6 +95,23 @@ export default defineConfig(({ command, mode }) => {
9295
server.middlewares.use(oAuthMiddleware);
9396
},
9497
},
98+
/**
99+
* Copy the `.htaccess` file to the `dist` directory.
100+
*/
101+
{
102+
name: 'htaccess-plugin',
103+
apply: 'build',
104+
writeBundle({ dir: outputDir }) {
105+
const htaccessPath = path('.htaccess');
106+
107+
if (existsSync(htaccessPath) && outputDir) {
108+
copyFileSync(
109+
htaccessPath,
110+
join(outputDir, '.htaccess')
111+
);
112+
}
113+
},
114+
} as Plugin,
95115
],
96116

97117
// Configuration for building your library.

0 commit comments

Comments
 (0)