diff --git a/examples/nuxt/nuxt.config.ts b/examples/nuxt/nuxt.config.ts index 9313f97..c47b08d 100644 --- a/examples/nuxt/nuxt.config.ts +++ b/examples/nuxt/nuxt.config.ts @@ -2,4 +2,4 @@ export default defineNuxtConfig({ modules: ["nitro-cloudflare-dev"], compatibilityDate: "2024-10-10", -}); \ No newline at end of file +}); diff --git a/src/index.ts b/src/index.ts index c207385..14ed1ca 100644 --- a/src/index.ts +++ b/src/index.ts @@ -90,7 +90,7 @@ async function nitroModule(nitro: Nitro) { // Dual compatibility with Nuxt and Nitro Modules export default function nitroCloudflareDev(arg1: unknown, arg2: unknown) { if ((arg2 as Nuxt)?.options?.nitro) { - (arg2 as Nuxt).hooks.hook("nitro:config", (nitroConfig) => { + (arg2 as Nuxt).hooks.hookOnce("nitro:config", (nitroConfig) => { nitroConfig.modules = nitroConfig.modules || []; nitroConfig.modules.push(nitroModule); }); diff --git a/src/runtime/plugin.dev.ts b/src/runtime/plugin.dev.ts index ef52793..d72d9d7 100644 --- a/src/runtime/plugin.dev.ts +++ b/src/runtime/plugin.dev.ts @@ -1,5 +1,5 @@ import type { NitroAppPlugin } from "nitropack"; -import type { PlatformProxy } from "wrangler"; +import type { GetPlatformProxyOptions, PlatformProxy } from "wrangler"; // @ts-ignore import { useRuntimeConfig, getRequestURL } from "#imports"; @@ -71,11 +71,16 @@ async function _getPlatformProxy() { }; } = useRuntimeConfig(); - const proxy = await getPlatformProxy({ + const proxyOptions: GetPlatformProxyOptions = { configPath: runtimeConfig.wrangler.configPath, persist: { path: runtimeConfig.wrangler.persistDir }, - environment: runtimeConfig.wrangler.environment, - }); + }; + // TODO: investigate why + // https://github.com/pi0/nitro-cloudflare-dev/issues/51 + if (runtimeConfig.wrangler.environment) { + proxyOptions.environment = runtimeConfig.wrangler.environment; + } + const proxy = await getPlatformProxy(proxyOptions); return proxy; }