Skip to content

Commit b0de564

Browse files
committed
fix(dev): proxy URL for https targets + disable auto-open by default
- Reconstruct target URL when the dev server path is /https://... (from window.fetch prefixing localhost); the old + path form produced an invalid URL and broke all proxied plugin requests. - Only open a browser when VITE_OPEN=true so missing xdg-open does not error.
1 parent 309cc99 commit b0de564

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

proxy.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ const proxySettingMiddleware: Connect.NextHandleFunction = (req, res) => {
5757
};
5858

5959
const proxyHandlerMiddle: Connect.NextHandleFunction = (req, res) => {
60-
const rawUrl = 'https:' + req.url;
60+
const path = req.url ?? '';
61+
/** Browser fetch becomes GET /https://host/... — must not use `https:` + path (breaks URL). */
62+
const rawUrl =
63+
path.startsWith('/https://') || path.startsWith('/http://')
64+
? path.slice(1)
65+
: `https:${path}`;
6166
if (req.headers['access-control-request-method']) {
6267
res.setHeader(
6368
'access-control-allow-methods',

vite.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export default defineConfig({
3131
},
3232
server: {
3333
port: 3000,
34-
open: true,
34+
// Opt-in: avoids `spawn xdg-open ENOENT` on minimal Linux; open http://localhost:3000 manually.
35+
open: process.env.VITE_OPEN === '1' || process.env.VITE_OPEN === 'true',
3536
},
3637
});

0 commit comments

Comments
 (0)