From a0187a660476a22009dccd1de36b8a01d6fcd044 Mon Sep 17 00:00:00 2001 From: Padreug Date: Sun, 3 May 2026 16:02:06 +0200 Subject: [PATCH] fix(vite): rewrite to .html when query has dots (JWT tokens) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The dev SPA-fallback plugin used `!req.url.includes('.')` to skip asset requests, which also matched JWT-shaped `?token=hdr.body.sig` query strings — so `localhost:5185/?token=...` fell through to the hub `index.html` instead of `market.html`, breaking the hub→standalone auth-relay link. Strip the query before the extension check. Applied to all 7 standalone vite configs. --- vite.activities.config.ts | 7 +++++-- vite.castle.config.ts | 7 +++++-- vite.chat.config.ts | 5 ++++- vite.forum.config.ts | 5 ++++- vite.market.config.ts | 5 ++++- vite.tasks.config.ts | 5 ++++- vite.wallet.config.ts | 5 ++++- 7 files changed, 30 insertions(+), 9 deletions(-) diff --git a/vite.activities.config.ts b/vite.activities.config.ts index aea9915..b7627e4 100644 --- a/vite.activities.config.ts +++ b/vite.activities.config.ts @@ -15,13 +15,16 @@ function activitiesHtmlPlugin(): Plugin { name: 'activities-html-rewrite', configureServer(server) { server.middlewares.use((req, _res, next) => { - // Rewrite all non-asset requests to activities.html + // Rewrite all non-asset requests to activities.html. + // Strip query before checking for an extension — JWTs (e.g. ?token=...) + // contain dots and would otherwise get mistaken for an asset request. + const path = req.url ? req.url.split('?')[0] : '' if ( req.url && !req.url.startsWith('/@') && !req.url.startsWith('/src/') && !req.url.startsWith('/node_modules/') && - !req.url.includes('.') // skip files with extensions + !path.includes('.') ) { req.url = '/activities.html' } diff --git a/vite.castle.config.ts b/vite.castle.config.ts index d0916eb..6ec7e0d 100644 --- a/vite.castle.config.ts +++ b/vite.castle.config.ts @@ -15,13 +15,16 @@ function castleHtmlPlugin(): Plugin { name: 'castle-html-rewrite', configureServer(server) { server.middlewares.use((req, _res, next) => { - // Rewrite all non-asset requests to castle.html + // Rewrite all non-asset requests to castle.html. + // Strip query before checking for an extension — JWTs (e.g. ?token=...) + // contain dots and would otherwise get mistaken for an asset request. + const path = req.url ? req.url.split('?')[0] : '' if ( req.url && !req.url.startsWith('/@') && !req.url.startsWith('/src/') && !req.url.startsWith('/node_modules/') && - !req.url.includes('.') // skip files with extensions + !path.includes('.') ) { req.url = '/castle.html' } diff --git a/vite.chat.config.ts b/vite.chat.config.ts index 6965d08..c28535f 100644 --- a/vite.chat.config.ts +++ b/vite.chat.config.ts @@ -11,12 +11,15 @@ function chatHtmlPlugin(): Plugin { name: 'chat-html-rewrite', configureServer(server) { server.middlewares.use((req, _res, next) => { + // Strip query before checking for an extension — JWTs (e.g. ?token=...) + // contain dots and would otherwise get mistaken for an asset request. + const path = req.url ? req.url.split('?')[0] : '' if ( req.url && !req.url.startsWith('/@') && !req.url.startsWith('/src/') && !req.url.startsWith('/node_modules/') && - !req.url.includes('.') + !path.includes('.') ) { req.url = '/chat.html' } diff --git a/vite.forum.config.ts b/vite.forum.config.ts index 756d5c1..0fdebbe 100644 --- a/vite.forum.config.ts +++ b/vite.forum.config.ts @@ -11,12 +11,15 @@ function forumHtmlPlugin(): Plugin { name: 'forum-html-rewrite', configureServer(server) { server.middlewares.use((req, _res, next) => { + // Strip query before checking for an extension — JWTs (e.g. ?token=...) + // contain dots and would otherwise get mistaken for an asset request. + const path = req.url ? req.url.split('?')[0] : '' if ( req.url && !req.url.startsWith('/@') && !req.url.startsWith('/src/') && !req.url.startsWith('/node_modules/') && - !req.url.includes('.') + !path.includes('.') ) { req.url = '/forum.html' } diff --git a/vite.market.config.ts b/vite.market.config.ts index 255d8c0..bf38430 100644 --- a/vite.market.config.ts +++ b/vite.market.config.ts @@ -11,12 +11,15 @@ function marketHtmlPlugin(): Plugin { name: 'market-html-rewrite', configureServer(server) { server.middlewares.use((req, _res, next) => { + // Strip query before checking for an extension — JWTs (e.g. ?token=...) + // contain dots and would otherwise get mistaken for an asset request. + const path = req.url ? req.url.split('?')[0] : '' if ( req.url && !req.url.startsWith('/@') && !req.url.startsWith('/src/') && !req.url.startsWith('/node_modules/') && - !req.url.includes('.') + !path.includes('.') ) { req.url = '/market.html' } diff --git a/vite.tasks.config.ts b/vite.tasks.config.ts index 3cb15fd..1edc3e6 100644 --- a/vite.tasks.config.ts +++ b/vite.tasks.config.ts @@ -11,12 +11,15 @@ function tasksHtmlPlugin(): Plugin { name: 'tasks-html-rewrite', configureServer(server) { server.middlewares.use((req, _res, next) => { + // Strip query before checking for an extension — JWTs (e.g. ?token=...) + // contain dots and would otherwise get mistaken for an asset request. + const path = req.url ? req.url.split('?')[0] : '' if ( req.url && !req.url.startsWith('/@') && !req.url.startsWith('/src/') && !req.url.startsWith('/node_modules/') && - !req.url.includes('.') + !path.includes('.') ) { req.url = '/tasks.html' } diff --git a/vite.wallet.config.ts b/vite.wallet.config.ts index dfa0bd6..f991672 100644 --- a/vite.wallet.config.ts +++ b/vite.wallet.config.ts @@ -15,12 +15,15 @@ function walletHtmlPlugin(): Plugin { name: 'wallet-html-rewrite', configureServer(server) { server.middlewares.use((req, _res, next) => { + // Strip query before checking for an extension — JWTs (e.g. ?token=...) + // contain dots and would otherwise get mistaken for an asset request. + const path = req.url ? req.url.split('?')[0] : '' if ( req.url && !req.url.startsWith('/@') && !req.url.startsWith('/src/') && !req.url.startsWith('/node_modules/') && - !req.url.includes('.') + !path.includes('.') ) { req.url = '/wallet.html' }