unplugin-https-reverse-proxy 4.0.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/nuxt.cjs CHANGED
@@ -14088,6 +14088,137 @@ ${line}
14088
14088
  }
14089
14089
  };
14090
14090
 
14091
+ // src/hmr-sse-bridge.ts
14092
+ var SSE_PATH = "/__hmr_sse";
14093
+ var SEND_PATH = "/__hmr_send";
14094
+ var MAX_POST_BODY = 64 * 1024;
14095
+ var hmrSseBridgeClientScript = `
14096
+ (function() {
14097
+ // Activate when served over HTTPS to bypass WSS self-signed cert issues
14098
+ if (location.protocol !== 'https:') return;
14099
+
14100
+ var OriginalWebSocket = window.WebSocket;
14101
+
14102
+ function SseWebSocket(originalUrl) {
14103
+ var self = this;
14104
+ // WebSocket readyState constants on instance
14105
+ self.CONNECTING = 0;
14106
+ self.OPEN = 1;
14107
+ self.CLOSING = 2;
14108
+ self.CLOSED = 3;
14109
+ self.readyState = 0;
14110
+ self.onopen = null;
14111
+ self.onmessage = null;
14112
+ self.onclose = null;
14113
+ self.onerror = null;
14114
+ self.bufferedAmount = 0;
14115
+ self.extensions = '';
14116
+ self.binaryType = 'blob';
14117
+ self.protocol = 'vite-hmr';
14118
+ self.url = originalUrl;
14119
+ self._listeners = {};
14120
+ self._opened = false;
14121
+
14122
+ var sseUrl = location.origin + '${SSE_PATH}';
14123
+ var sendUrl = location.origin + '${SEND_PATH}';
14124
+ self._sendUrl = sendUrl;
14125
+
14126
+ var es = new EventSource(sseUrl);
14127
+ self._es = es;
14128
+
14129
+ es.onopen = function() {
14130
+ if (self._opened) return;
14131
+ self._opened = true;
14132
+ self.readyState = 1;
14133
+ var evt = new Event('open');
14134
+ if (self.onopen) self.onopen(evt);
14135
+ self._emit('open', evt);
14136
+ };
14137
+
14138
+ es.onmessage = function(e) {
14139
+ var evt = new MessageEvent('message', { data: e.data });
14140
+ if (self.onmessage) self.onmessage(evt);
14141
+ self._emit('message', evt);
14142
+ };
14143
+
14144
+ es.onerror = function() {
14145
+ // EventSource auto-reconnects on error; don't treat as fatal close
14146
+ // Only emit error event, never close event (SSE handles reconnect internally)
14147
+ if (self.readyState >= 2) return;
14148
+ // EventSource auto-reconnects; no action needed
14149
+ };
14150
+ }
14151
+
14152
+ SseWebSocket.prototype.send = function(data) {
14153
+ if (this.readyState !== 1) return;
14154
+ fetch(this._sendUrl, {
14155
+ method: 'POST',
14156
+ headers: { 'Content-Type': 'application/json' },
14157
+ body: data
14158
+ }).catch(function() {});
14159
+ };
14160
+
14161
+ SseWebSocket.prototype.close = function() {
14162
+ if (this.readyState >= 2) return;
14163
+ this.readyState = 3;
14164
+ if (this._es) this._es.close();
14165
+ var evt = new CloseEvent('close', { code: 1000, reason: '', wasClean: true });
14166
+ if (this.onclose) this.onclose(evt);
14167
+ this._emit('close', evt);
14168
+ };
14169
+
14170
+ SseWebSocket.prototype.addEventListener = function(type, fn, options) {
14171
+ if (!this._listeners[type]) this._listeners[type] = [];
14172
+ var entry = { fn: fn, once: !!(options && options.once) };
14173
+ this._listeners[type].push(entry);
14174
+ };
14175
+
14176
+ SseWebSocket.prototype.removeEventListener = function(type, fn) {
14177
+ var list = this._listeners[type];
14178
+ if (!list) return;
14179
+ this._listeners[type] = list.filter(function(e) { return e.fn !== fn; });
14180
+ };
14181
+
14182
+ SseWebSocket.prototype.dispatchEvent = function(evt) {
14183
+ this._emit(evt.type, evt);
14184
+ return true;
14185
+ };
14186
+
14187
+ SseWebSocket.prototype._emit = function(type, evt) {
14188
+ var list = this._listeners[type];
14189
+ if (!list) return;
14190
+ var remaining = [];
14191
+ list.forEach(function(entry) {
14192
+ entry.fn(evt);
14193
+ if (!entry.once) remaining.push(entry);
14194
+ });
14195
+ this._listeners[type] = remaining;
14196
+ };
14197
+
14198
+ function PatchedWebSocket(url, protocols) {
14199
+ // Only intercept Vite HMR connections (protocol 'vite-hmr')
14200
+ var isViteHmr = protocols === 'vite-hmr'
14201
+ || (Array.isArray(protocols) && protocols.indexOf('vite-hmr') !== -1);
14202
+ if (!isViteHmr) {
14203
+ if (protocols !== undefined) {
14204
+ return new OriginalWebSocket(url, protocols);
14205
+ }
14206
+ return new OriginalWebSocket(url);
14207
+ }
14208
+ return new SseWebSocket(url);
14209
+ }
14210
+
14211
+ PatchedWebSocket.CONNECTING = 0;
14212
+ PatchedWebSocket.OPEN = 1;
14213
+ PatchedWebSocket.CLOSING = 2;
14214
+ PatchedWebSocket.CLOSED = 3;
14215
+ PatchedWebSocket.prototype = Object.create(OriginalWebSocket.prototype);
14216
+ PatchedWebSocket.prototype.constructor = PatchedWebSocket;
14217
+
14218
+ window.WebSocket = PatchedWebSocket;
14219
+ })();
14220
+ `;
14221
+
14091
14222
  // src/index.ts
14092
14223
  var caddy;
14093
14224
  var cwd = import_node_process5.default.cwd();
package/dist/nuxt.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  vitePrintUrls
3
- } from "./chunk-K7HSLE6X.js";
3
+ } from "./chunk-QURDG7SD.js";
4
+ import "./chunk-RSBXFJ3Z.js";
4
5
  import {
5
6
  consola,
6
7
  isAdmin
package/dist/rollup.cjs CHANGED
@@ -14087,9 +14087,238 @@ ${line}
14087
14087
  }
14088
14088
  };
14089
14089
 
14090
+ // src/hmr-sse-bridge.ts
14091
+ var SSE_PATH = "/__hmr_sse";
14092
+ var SEND_PATH = "/__hmr_send";
14093
+ var MAX_POST_BODY = 64 * 1024;
14094
+ function setupHmrSseBridge(server) {
14095
+ const sseClients = /* @__PURE__ */ new Set();
14096
+ const originalSend = server.ws.send.bind(server.ws);
14097
+ server.ws.send = (...args2) => {
14098
+ ;
14099
+ originalSend(...args2);
14100
+ let payload;
14101
+ if (typeof args2[0] === "string") {
14102
+ payload = JSON.stringify({ type: "custom", event: args2[0], data: args2[1] });
14103
+ } else {
14104
+ payload = JSON.stringify(args2[0]);
14105
+ }
14106
+ for (const res of sseClients) {
14107
+ try {
14108
+ res.write(`data: ${payload}
14109
+
14110
+ `);
14111
+ } catch {
14112
+ sseClients.delete(res);
14113
+ }
14114
+ }
14115
+ };
14116
+ server.middlewares.use((req, res, next2) => {
14117
+ var _a4;
14118
+ const url2 = (_a4 = req.url) == null ? void 0 : _a4.split("?")[0];
14119
+ if (url2 === SSE_PATH && req.method === "GET") {
14120
+ handleSseConnection(req, res, sseClients);
14121
+ return;
14122
+ }
14123
+ if (url2 === SEND_PATH && req.method === "POST") {
14124
+ handleClientMessage(req, res, server);
14125
+ return;
14126
+ }
14127
+ next2();
14128
+ });
14129
+ }
14130
+ function handleSseConnection(_req, res, sseClients) {
14131
+ res.writeHead(200, {
14132
+ "Content-Type": "text/event-stream",
14133
+ "Cache-Control": "no-cache",
14134
+ "Connection": "keep-alive"
14135
+ });
14136
+ res.write(`data: ${JSON.stringify({ type: "connected" })}
14137
+
14138
+ `);
14139
+ sseClients.add(res);
14140
+ const keepAlive = setInterval(() => {
14141
+ try {
14142
+ res.write(": ping\n\n");
14143
+ } catch {
14144
+ cleanup();
14145
+ }
14146
+ }, 3e4);
14147
+ function cleanup() {
14148
+ clearInterval(keepAlive);
14149
+ sseClients.delete(res);
14150
+ }
14151
+ res.on("close", cleanup);
14152
+ res.on("error", cleanup);
14153
+ }
14154
+ function handleClientMessage(req, res, server) {
14155
+ let body = "";
14156
+ let overflow = false;
14157
+ req.on("data", (chunk) => {
14158
+ body += chunk.toString();
14159
+ if (body.length > MAX_POST_BODY) {
14160
+ overflow = true;
14161
+ req.destroy();
14162
+ }
14163
+ });
14164
+ req.on("end", () => {
14165
+ var _a4, _b3, _c2, _d2, _e;
14166
+ if (overflow) {
14167
+ res.writeHead(413);
14168
+ res.end('{"ok":false}');
14169
+ return;
14170
+ }
14171
+ try {
14172
+ const data = JSON.parse(body);
14173
+ if (data.type === "custom" && data.event) {
14174
+ const dummyClient = {
14175
+ send: (...args2) => {
14176
+ server.ws.send(...args2);
14177
+ }
14178
+ };
14179
+ (_e = (_d2 = (_c2 = (_b3 = (_a4 = server.environments) == null ? void 0 : _a4.client) == null ? void 0 : _b3.hot) == null ? void 0 : _c2.api) == null ? void 0 : _d2.emit) == null ? void 0 : _e.call(_d2, data.event, data.data, dummyClient);
14180
+ }
14181
+ res.writeHead(200, {
14182
+ "Content-Type": "application/json"
14183
+ });
14184
+ res.end('{"ok":true}');
14185
+ } catch {
14186
+ res.writeHead(400);
14187
+ res.end('{"ok":false}');
14188
+ }
14189
+ });
14190
+ }
14191
+ var hmrSseBridgeClientScript = `
14192
+ (function() {
14193
+ // Activate when served over HTTPS to bypass WSS self-signed cert issues
14194
+ if (location.protocol !== 'https:') return;
14195
+
14196
+ var OriginalWebSocket = window.WebSocket;
14197
+
14198
+ function SseWebSocket(originalUrl) {
14199
+ var self = this;
14200
+ // WebSocket readyState constants on instance
14201
+ self.CONNECTING = 0;
14202
+ self.OPEN = 1;
14203
+ self.CLOSING = 2;
14204
+ self.CLOSED = 3;
14205
+ self.readyState = 0;
14206
+ self.onopen = null;
14207
+ self.onmessage = null;
14208
+ self.onclose = null;
14209
+ self.onerror = null;
14210
+ self.bufferedAmount = 0;
14211
+ self.extensions = '';
14212
+ self.binaryType = 'blob';
14213
+ self.protocol = 'vite-hmr';
14214
+ self.url = originalUrl;
14215
+ self._listeners = {};
14216
+ self._opened = false;
14217
+
14218
+ var sseUrl = location.origin + '${SSE_PATH}';
14219
+ var sendUrl = location.origin + '${SEND_PATH}';
14220
+ self._sendUrl = sendUrl;
14221
+
14222
+ var es = new EventSource(sseUrl);
14223
+ self._es = es;
14224
+
14225
+ es.onopen = function() {
14226
+ if (self._opened) return;
14227
+ self._opened = true;
14228
+ self.readyState = 1;
14229
+ var evt = new Event('open');
14230
+ if (self.onopen) self.onopen(evt);
14231
+ self._emit('open', evt);
14232
+ };
14233
+
14234
+ es.onmessage = function(e) {
14235
+ var evt = new MessageEvent('message', { data: e.data });
14236
+ if (self.onmessage) self.onmessage(evt);
14237
+ self._emit('message', evt);
14238
+ };
14239
+
14240
+ es.onerror = function() {
14241
+ // EventSource auto-reconnects on error; don't treat as fatal close
14242
+ // Only emit error event, never close event (SSE handles reconnect internally)
14243
+ if (self.readyState >= 2) return;
14244
+ // EventSource auto-reconnects; no action needed
14245
+ };
14246
+ }
14247
+
14248
+ SseWebSocket.prototype.send = function(data) {
14249
+ if (this.readyState !== 1) return;
14250
+ fetch(this._sendUrl, {
14251
+ method: 'POST',
14252
+ headers: { 'Content-Type': 'application/json' },
14253
+ body: data
14254
+ }).catch(function() {});
14255
+ };
14256
+
14257
+ SseWebSocket.prototype.close = function() {
14258
+ if (this.readyState >= 2) return;
14259
+ this.readyState = 3;
14260
+ if (this._es) this._es.close();
14261
+ var evt = new CloseEvent('close', { code: 1000, reason: '', wasClean: true });
14262
+ if (this.onclose) this.onclose(evt);
14263
+ this._emit('close', evt);
14264
+ };
14265
+
14266
+ SseWebSocket.prototype.addEventListener = function(type, fn, options) {
14267
+ if (!this._listeners[type]) this._listeners[type] = [];
14268
+ var entry = { fn: fn, once: !!(options && options.once) };
14269
+ this._listeners[type].push(entry);
14270
+ };
14271
+
14272
+ SseWebSocket.prototype.removeEventListener = function(type, fn) {
14273
+ var list = this._listeners[type];
14274
+ if (!list) return;
14275
+ this._listeners[type] = list.filter(function(e) { return e.fn !== fn; });
14276
+ };
14277
+
14278
+ SseWebSocket.prototype.dispatchEvent = function(evt) {
14279
+ this._emit(evt.type, evt);
14280
+ return true;
14281
+ };
14282
+
14283
+ SseWebSocket.prototype._emit = function(type, evt) {
14284
+ var list = this._listeners[type];
14285
+ if (!list) return;
14286
+ var remaining = [];
14287
+ list.forEach(function(entry) {
14288
+ entry.fn(evt);
14289
+ if (!entry.once) remaining.push(entry);
14290
+ });
14291
+ this._listeners[type] = remaining;
14292
+ };
14293
+
14294
+ function PatchedWebSocket(url, protocols) {
14295
+ // Only intercept Vite HMR connections (protocol 'vite-hmr')
14296
+ var isViteHmr = protocols === 'vite-hmr'
14297
+ || (Array.isArray(protocols) && protocols.indexOf('vite-hmr') !== -1);
14298
+ if (!isViteHmr) {
14299
+ if (protocols !== undefined) {
14300
+ return new OriginalWebSocket(url, protocols);
14301
+ }
14302
+ return new OriginalWebSocket(url);
14303
+ }
14304
+ return new SseWebSocket(url);
14305
+ }
14306
+
14307
+ PatchedWebSocket.CONNECTING = 0;
14308
+ PatchedWebSocket.OPEN = 1;
14309
+ PatchedWebSocket.CLOSING = 2;
14310
+ PatchedWebSocket.CLOSED = 3;
14311
+ PatchedWebSocket.prototype = Object.create(OriginalWebSocket.prototype);
14312
+ PatchedWebSocket.prototype.constructor = PatchedWebSocket;
14313
+
14314
+ window.WebSocket = PatchedWebSocket;
14315
+ })();
14316
+ `;
14317
+
14090
14318
  // src/index.ts
14091
14319
  var config;
14092
14320
  var caddy;
14321
+ var hmrSseBridgeActive = false;
14093
14322
  var cwd = import_node_process5.default.cwd();
14094
14323
  function colorUrl(url2) {
14095
14324
  return import_picocolors2.default.green(url2.replace(/:(\d+)\//, (_, port) => `:${import_picocolors2.default.bold(port)}/`));
@@ -14176,6 +14405,20 @@ var unpluginFactory = (options) => ({
14176
14405
  }
14177
14406
  const base = server.config.base || "/";
14178
14407
  server.printUrls = () => vitePrintUrls(options, source, target, base, _printUrls);
14408
+ if (options.https) {
14409
+ setupHmrSseBridge(server);
14410
+ hmrSseBridgeActive = true;
14411
+ consola.info("HMR SSE bridge enabled for iOS Safari WSS workaround");
14412
+ }
14413
+ },
14414
+ transformIndexHtml() {
14415
+ if (!hmrSseBridgeActive)
14416
+ return [];
14417
+ return [{
14418
+ tag: "script",
14419
+ children: hmrSseBridgeClientScript,
14420
+ injectTo: "head-prepend"
14421
+ }];
14179
14422
  }
14180
14423
  },
14181
14424
  webpack(compiler) {
package/dist/rollup.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-K7HSLE6X.js";
3
+ } from "./chunk-QURDG7SD.js";
4
+ import "./chunk-RSBXFJ3Z.js";
4
5
  import "./chunk-2P7SUCQ3.js";
5
6
 
6
7
  // src/rollup.ts
package/dist/rspack.cjs CHANGED
@@ -14086,9 +14086,238 @@ ${line}
14086
14086
  }
14087
14087
  };
14088
14088
 
14089
+ // src/hmr-sse-bridge.ts
14090
+ var SSE_PATH = "/__hmr_sse";
14091
+ var SEND_PATH = "/__hmr_send";
14092
+ var MAX_POST_BODY = 64 * 1024;
14093
+ function setupHmrSseBridge(server) {
14094
+ const sseClients = /* @__PURE__ */ new Set();
14095
+ const originalSend = server.ws.send.bind(server.ws);
14096
+ server.ws.send = (...args2) => {
14097
+ ;
14098
+ originalSend(...args2);
14099
+ let payload;
14100
+ if (typeof args2[0] === "string") {
14101
+ payload = JSON.stringify({ type: "custom", event: args2[0], data: args2[1] });
14102
+ } else {
14103
+ payload = JSON.stringify(args2[0]);
14104
+ }
14105
+ for (const res of sseClients) {
14106
+ try {
14107
+ res.write(`data: ${payload}
14108
+
14109
+ `);
14110
+ } catch {
14111
+ sseClients.delete(res);
14112
+ }
14113
+ }
14114
+ };
14115
+ server.middlewares.use((req, res, next2) => {
14116
+ var _a4;
14117
+ const url2 = (_a4 = req.url) == null ? void 0 : _a4.split("?")[0];
14118
+ if (url2 === SSE_PATH && req.method === "GET") {
14119
+ handleSseConnection(req, res, sseClients);
14120
+ return;
14121
+ }
14122
+ if (url2 === SEND_PATH && req.method === "POST") {
14123
+ handleClientMessage(req, res, server);
14124
+ return;
14125
+ }
14126
+ next2();
14127
+ });
14128
+ }
14129
+ function handleSseConnection(_req, res, sseClients) {
14130
+ res.writeHead(200, {
14131
+ "Content-Type": "text/event-stream",
14132
+ "Cache-Control": "no-cache",
14133
+ "Connection": "keep-alive"
14134
+ });
14135
+ res.write(`data: ${JSON.stringify({ type: "connected" })}
14136
+
14137
+ `);
14138
+ sseClients.add(res);
14139
+ const keepAlive = setInterval(() => {
14140
+ try {
14141
+ res.write(": ping\n\n");
14142
+ } catch {
14143
+ cleanup();
14144
+ }
14145
+ }, 3e4);
14146
+ function cleanup() {
14147
+ clearInterval(keepAlive);
14148
+ sseClients.delete(res);
14149
+ }
14150
+ res.on("close", cleanup);
14151
+ res.on("error", cleanup);
14152
+ }
14153
+ function handleClientMessage(req, res, server) {
14154
+ let body = "";
14155
+ let overflow = false;
14156
+ req.on("data", (chunk) => {
14157
+ body += chunk.toString();
14158
+ if (body.length > MAX_POST_BODY) {
14159
+ overflow = true;
14160
+ req.destroy();
14161
+ }
14162
+ });
14163
+ req.on("end", () => {
14164
+ var _a4, _b3, _c2, _d2, _e;
14165
+ if (overflow) {
14166
+ res.writeHead(413);
14167
+ res.end('{"ok":false}');
14168
+ return;
14169
+ }
14170
+ try {
14171
+ const data = JSON.parse(body);
14172
+ if (data.type === "custom" && data.event) {
14173
+ const dummyClient = {
14174
+ send: (...args2) => {
14175
+ server.ws.send(...args2);
14176
+ }
14177
+ };
14178
+ (_e = (_d2 = (_c2 = (_b3 = (_a4 = server.environments) == null ? void 0 : _a4.client) == null ? void 0 : _b3.hot) == null ? void 0 : _c2.api) == null ? void 0 : _d2.emit) == null ? void 0 : _e.call(_d2, data.event, data.data, dummyClient);
14179
+ }
14180
+ res.writeHead(200, {
14181
+ "Content-Type": "application/json"
14182
+ });
14183
+ res.end('{"ok":true}');
14184
+ } catch {
14185
+ res.writeHead(400);
14186
+ res.end('{"ok":false}');
14187
+ }
14188
+ });
14189
+ }
14190
+ var hmrSseBridgeClientScript = `
14191
+ (function() {
14192
+ // Activate when served over HTTPS to bypass WSS self-signed cert issues
14193
+ if (location.protocol !== 'https:') return;
14194
+
14195
+ var OriginalWebSocket = window.WebSocket;
14196
+
14197
+ function SseWebSocket(originalUrl) {
14198
+ var self = this;
14199
+ // WebSocket readyState constants on instance
14200
+ self.CONNECTING = 0;
14201
+ self.OPEN = 1;
14202
+ self.CLOSING = 2;
14203
+ self.CLOSED = 3;
14204
+ self.readyState = 0;
14205
+ self.onopen = null;
14206
+ self.onmessage = null;
14207
+ self.onclose = null;
14208
+ self.onerror = null;
14209
+ self.bufferedAmount = 0;
14210
+ self.extensions = '';
14211
+ self.binaryType = 'blob';
14212
+ self.protocol = 'vite-hmr';
14213
+ self.url = originalUrl;
14214
+ self._listeners = {};
14215
+ self._opened = false;
14216
+
14217
+ var sseUrl = location.origin + '${SSE_PATH}';
14218
+ var sendUrl = location.origin + '${SEND_PATH}';
14219
+ self._sendUrl = sendUrl;
14220
+
14221
+ var es = new EventSource(sseUrl);
14222
+ self._es = es;
14223
+
14224
+ es.onopen = function() {
14225
+ if (self._opened) return;
14226
+ self._opened = true;
14227
+ self.readyState = 1;
14228
+ var evt = new Event('open');
14229
+ if (self.onopen) self.onopen(evt);
14230
+ self._emit('open', evt);
14231
+ };
14232
+
14233
+ es.onmessage = function(e) {
14234
+ var evt = new MessageEvent('message', { data: e.data });
14235
+ if (self.onmessage) self.onmessage(evt);
14236
+ self._emit('message', evt);
14237
+ };
14238
+
14239
+ es.onerror = function() {
14240
+ // EventSource auto-reconnects on error; don't treat as fatal close
14241
+ // Only emit error event, never close event (SSE handles reconnect internally)
14242
+ if (self.readyState >= 2) return;
14243
+ // EventSource auto-reconnects; no action needed
14244
+ };
14245
+ }
14246
+
14247
+ SseWebSocket.prototype.send = function(data) {
14248
+ if (this.readyState !== 1) return;
14249
+ fetch(this._sendUrl, {
14250
+ method: 'POST',
14251
+ headers: { 'Content-Type': 'application/json' },
14252
+ body: data
14253
+ }).catch(function() {});
14254
+ };
14255
+
14256
+ SseWebSocket.prototype.close = function() {
14257
+ if (this.readyState >= 2) return;
14258
+ this.readyState = 3;
14259
+ if (this._es) this._es.close();
14260
+ var evt = new CloseEvent('close', { code: 1000, reason: '', wasClean: true });
14261
+ if (this.onclose) this.onclose(evt);
14262
+ this._emit('close', evt);
14263
+ };
14264
+
14265
+ SseWebSocket.prototype.addEventListener = function(type, fn, options) {
14266
+ if (!this._listeners[type]) this._listeners[type] = [];
14267
+ var entry = { fn: fn, once: !!(options && options.once) };
14268
+ this._listeners[type].push(entry);
14269
+ };
14270
+
14271
+ SseWebSocket.prototype.removeEventListener = function(type, fn) {
14272
+ var list = this._listeners[type];
14273
+ if (!list) return;
14274
+ this._listeners[type] = list.filter(function(e) { return e.fn !== fn; });
14275
+ };
14276
+
14277
+ SseWebSocket.prototype.dispatchEvent = function(evt) {
14278
+ this._emit(evt.type, evt);
14279
+ return true;
14280
+ };
14281
+
14282
+ SseWebSocket.prototype._emit = function(type, evt) {
14283
+ var list = this._listeners[type];
14284
+ if (!list) return;
14285
+ var remaining = [];
14286
+ list.forEach(function(entry) {
14287
+ entry.fn(evt);
14288
+ if (!entry.once) remaining.push(entry);
14289
+ });
14290
+ this._listeners[type] = remaining;
14291
+ };
14292
+
14293
+ function PatchedWebSocket(url, protocols) {
14294
+ // Only intercept Vite HMR connections (protocol 'vite-hmr')
14295
+ var isViteHmr = protocols === 'vite-hmr'
14296
+ || (Array.isArray(protocols) && protocols.indexOf('vite-hmr') !== -1);
14297
+ if (!isViteHmr) {
14298
+ if (protocols !== undefined) {
14299
+ return new OriginalWebSocket(url, protocols);
14300
+ }
14301
+ return new OriginalWebSocket(url);
14302
+ }
14303
+ return new SseWebSocket(url);
14304
+ }
14305
+
14306
+ PatchedWebSocket.CONNECTING = 0;
14307
+ PatchedWebSocket.OPEN = 1;
14308
+ PatchedWebSocket.CLOSING = 2;
14309
+ PatchedWebSocket.CLOSED = 3;
14310
+ PatchedWebSocket.prototype = Object.create(OriginalWebSocket.prototype);
14311
+ PatchedWebSocket.prototype.constructor = PatchedWebSocket;
14312
+
14313
+ window.WebSocket = PatchedWebSocket;
14314
+ })();
14315
+ `;
14316
+
14089
14317
  // src/index.ts
14090
14318
  var config;
14091
14319
  var caddy;
14320
+ var hmrSseBridgeActive = false;
14092
14321
  var cwd = import_node_process5.default.cwd();
14093
14322
  function colorUrl(url2) {
14094
14323
  return import_picocolors2.default.green(url2.replace(/:(\d+)\//, (_, port) => `:${import_picocolors2.default.bold(port)}/`));
@@ -14175,6 +14404,20 @@ var unpluginFactory = (options) => ({
14175
14404
  }
14176
14405
  const base = server.config.base || "/";
14177
14406
  server.printUrls = () => vitePrintUrls(options, source, target, base, _printUrls);
14407
+ if (options.https) {
14408
+ setupHmrSseBridge(server);
14409
+ hmrSseBridgeActive = true;
14410
+ consola.info("HMR SSE bridge enabled for iOS Safari WSS workaround");
14411
+ }
14412
+ },
14413
+ transformIndexHtml() {
14414
+ if (!hmrSseBridgeActive)
14415
+ return [];
14416
+ return [{
14417
+ tag: "script",
14418
+ children: hmrSseBridgeClientScript,
14419
+ injectTo: "head-prepend"
14420
+ }];
14178
14421
  }
14179
14422
  },
14180
14423
  webpack(compiler) {
package/dist/rspack.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  src_default
3
- } from "./chunk-K7HSLE6X.js";
3
+ } from "./chunk-QURDG7SD.js";
4
+ import "./chunk-RSBXFJ3Z.js";
4
5
  import "./chunk-2P7SUCQ3.js";
5
6
 
6
7
  // src/rspack.ts