Skip to content

Commit 6fec899

Browse files
committed
fix: avoid getting stuck during nuxt prepare
1 parent b74cddc commit 6fec899

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

examples/nuxt/nuxt.config.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
// https://nuxt.com/docs/api/configuration/nuxt-config
22
export default defineNuxtConfig({
33
devtools: { enabled: true },
4-
// uncomment to enable the plugin
5-
// modules: [
6-
// ['~/../../../src/nuxt', {
7-
// enabled: true,
8-
// target: 'test-nuxt.abc.com',
9-
// }],
10-
// ],
4+
modules: [
5+
['~/../../../src/nuxt', {
6+
enabled: true,
7+
target: 'test-nuxt.abc.com',
8+
}],
9+
],
1110
})

src/caddy/index.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,14 @@ interface RunOptions {
105105
health_check?: boolean
106106
}
107107

108-
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+
}
109116

110117
export class CaddyInstant {
111118
private inited = false
@@ -204,10 +211,12 @@ export class CaddyInstant {
204211
},
205212
]
206213

214+
const { writeCaddyConfig } = getCaddyConfig()
207215
writeCaddyConfig(proxies)
208216

209217
this._stopEffects.push(
210218
effect(async () => {
219+
const { configJsonRef } = getCaddyConfig()
211220
const proxies = Object.values(configJsonRef() || {})
212221
if (!(this.caddyfile || '').includes(`${target.split(':')[0]}${https ? '' : ':80'}`)) {
213222
const ctx = validateTemplateContext({
@@ -368,7 +377,9 @@ export class CaddyInstant {
368377
await lockfile.unlock(caddyLockFilePath).catch(() => { })
369378
await unlink(caddyFilePath).catch(() => { })
370379
await unlink(caddyLockFilePath).catch(() => { })
371-
await cleanUp()
380+
if (caddyConfig) {
381+
await caddyConfig.cleanUp()
382+
}
372383
}
373384
catch (e) {
374385
consola.error(e)

0 commit comments

Comments
 (0)