unplugin-https-reverse-proxy 4.0.0 → 4.0.2

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/src/index.ts CHANGED
@@ -6,12 +6,15 @@ import { Table } from 'console-table-printer'
6
6
  import c from 'picocolors'
7
7
  import { createUnplugin } from 'unplugin'
8
8
  import { CaddyInstant } from './caddy'
9
+ import { hmrSseBridgeClientScript, setupHmrSseBridge } from './hmr-sse-bridge'
9
10
  import { consola, generateQrcode, getIpv4List, isAdmin, once } from './utils'
10
11
 
11
12
  let config: ResolvedConfig
12
13
 
13
14
  let caddy: CaddyInstant
14
15
 
16
+ let hmrSseBridgeActive = false
17
+
15
18
  const cwd = process.cwd()
16
19
 
17
20
  function colorUrl(url: string): string {
@@ -119,6 +122,23 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
119
122
  const base = server.config.base || '/'
120
123
 
121
124
  server.printUrls = () => vitePrintUrls(options, source, target, base, _printUrls)
125
+
126
+ // Setup SSE bridge for iOS Safari WSS workaround
127
+ if (options.https) {
128
+ setupHmrSseBridge(server)
129
+ hmrSseBridgeActive = true
130
+ consola.info('HMR SSE bridge enabled for iOS Safari WSS workaround')
131
+ }
132
+ },
133
+ transformIndexHtml() {
134
+ if (!hmrSseBridgeActive)
135
+ return []
136
+ // Inject client-side script to patch WebSocket on iOS Safari
137
+ return [{
138
+ tag: 'script',
139
+ children: hmrSseBridgeClientScript,
140
+ injectTo: 'head-prepend',
141
+ }]
122
142
  },
123
143
  },
124
144
  webpack(compiler) {