unplugin-https-reverse-proxy 2.0.3-beta.1 → 3.0.0

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.
@@ -44,7 +44,7 @@ export function useCaddyConfig(): {
44
44
  const proxies = configJsonRef() || {}
45
45
 
46
46
  _proxies.forEach((p) => {
47
- const index = `${p.target}${p.port_suffix}`
47
+ const index = `${p.target}${p.portSuffix}`
48
48
  proxies[index] = p
49
49
  })
50
50
 
@@ -102,9 +102,17 @@ interface RunOptions {
102
102
  base: string
103
103
  showCaddyLog: boolean
104
104
  https: boolean
105
+ healthCheck?: boolean
105
106
  }
106
107
 
107
- const { cleanUp, configJsonRef, writeCaddyConfig } = useCaddyConfig()
108
+ let caddyConfig: ReturnType<typeof useCaddyConfig> | undefined
109
+
110
+ function getCaddyConfig(): ReturnType<typeof useCaddyConfig> {
111
+ if (!caddyConfig) {
112
+ caddyConfig = useCaddyConfig()
113
+ }
114
+ return caddyConfig
115
+ }
108
116
 
109
117
  export class CaddyInstant {
110
118
  private inited = false
@@ -177,6 +185,7 @@ export class CaddyInstant {
177
185
  base = '/',
178
186
  showCaddyLog = false,
179
187
  https = false,
188
+ healthCheck = true,
180
189
  } = options || {}
181
190
 
182
191
  this._source = source
@@ -194,17 +203,20 @@ export class CaddyInstant {
194
203
  const proxies = [
195
204
  {
196
205
  target: targetHost,
197
- port_suffix: https ? '' : ':80',
206
+ portSuffix: https ? '' : ':80',
198
207
  tls: https ? 'tls internal' : '',
199
208
  source,
200
209
  base,
210
+ healthCheck,
201
211
  },
202
212
  ]
203
213
 
214
+ const { writeCaddyConfig } = getCaddyConfig()
204
215
  writeCaddyConfig(proxies)
205
216
 
206
217
  this._stopEffects.push(
207
218
  effect(async () => {
219
+ const { configJsonRef } = getCaddyConfig()
208
220
  const proxies = Object.values(configJsonRef() || {})
209
221
  if (!(this.caddyfile || '').includes(`${target.split(':')[0]}${https ? '' : ':80'}`)) {
210
222
  const ctx = validateTemplateContext({
@@ -365,7 +377,9 @@ export class CaddyInstant {
365
377
  await lockfile.unlock(caddyLockFilePath).catch(() => { })
366
378
  await unlink(caddyFilePath).catch(() => { })
367
379
  await unlink(caddyLockFilePath).catch(() => { })
368
- await cleanUp()
380
+ if (caddyConfig) {
381
+ await caddyConfig.cleanUp()
382
+ }
369
383
  }
370
384
  catch (e) {
371
385
  consola.error(e)
package/src/types.ts CHANGED
@@ -5,4 +5,5 @@ export interface Options {
5
5
  showCaddyLog?: boolean
6
6
  /** default `false` */
7
7
  https?: boolean
8
+ healthCheck?: boolean
8
9
  }