Skip to content

Commit

Permalink
fix: proxy requests to olm.wasm through the web worker to avoid the n…
Browse files Browse the repository at this point in the history
…eed for server rewrite rules.
  • Loading branch information
zicklag committed Dec 27, 2024
1 parent 83203e0 commit 3582372
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
10 changes: 10 additions & 0 deletions src/sw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ const matrixShim = MatrixShim.init();

self.addEventListener('fetch', async (event: FetchEvent) => {
const url = new URL(event.request.url);

// TODO(@zicklag): This is a weird thing we are doing to replace the need
// for the nginx / fastly / etc. rewrite rules that were previously being used.
// I'm not sure why this WASM binary is always resolved with a relative path,
// but it would be good to fix that so that we don't need this anymore.
if (url.pathname.endsWith('olm.wasm')) {
event.respondWith(fetch('/olm.wasm'))
return
}

if (url.pathname.startsWith('/_matrix')) {
const shim = await matrixShim;
event.respondWith(shim.handleRequest(event.request));
Expand Down
13 changes: 7 additions & 6 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ export default defineConfig({
server: {
port: 8080,
host: true,
proxy: {
'^\\/.*?\\/olm\\.wasm$': {
target: 'http://localhost:8080',
rewrite: () => '/olm.wasm',
},
},
// Not needed after working the rewrite into the web worker.
// proxy: {
// '^\\/.*?\\/olm\\.wasm$': {
// target: 'http://localhost:8080',
// rewrite: () => '/olm.wasm',
// },
// },
},
plugins: [
topLevelAwait({
Expand Down

0 comments on commit 3582372

Please sign in to comment.