From 713c45e9431f206b543877bc1f4f1f58e71df664 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Mon, 21 Oct 2024 14:41:12 +0200 Subject: [PATCH 1/6] fix(wrangler): only set environment if defined --- examples/nuxt/nuxt.config.ts | 4 ++-- src/index.ts | 2 +- src/runtime/plugin.dev.ts | 11 +++++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/examples/nuxt/nuxt.config.ts b/examples/nuxt/nuxt.config.ts index 9313f97..6a99c04 100644 --- a/examples/nuxt/nuxt.config.ts +++ b/examples/nuxt/nuxt.config.ts @@ -1,5 +1,5 @@ // https://nuxt.com/docs/api/configuration/nuxt-config export default defineNuxtConfig({ modules: ["nitro-cloudflare-dev"], - compatibilityDate: "2024-10-10", -}); \ No newline at end of file + compatibilityDate: "2024-10-10" +}); 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..376a8fb 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,14 @@ async function _getPlatformProxy() { }; } = useRuntimeConfig(); - const proxy = await getPlatformProxy({ + const proxyOptions: GetPlatformProxyOptions = { configPath: runtimeConfig.wrangler.configPath, persist: { path: runtimeConfig.wrangler.persistDir }, - environment: runtimeConfig.wrangler.environment, - }); + }; + if (runtimeConfig.wrangler.environment) { + proxyOptions.environment = runtimeConfig.wrangler.environment; + } + const proxy = await getPlatformProxy(proxyOptions); return proxy; } From c013a53610f7fb60b63b5029e3e4abd0d181ad31 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Tue, 22 Oct 2024 19:52:00 +0900 Subject: [PATCH 2/6] Update src/runtime/plugin.dev.ts --- src/runtime/plugin.dev.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/runtime/plugin.dev.ts b/src/runtime/plugin.dev.ts index 376a8fb..d72d9d7 100644 --- a/src/runtime/plugin.dev.ts +++ b/src/runtime/plugin.dev.ts @@ -75,6 +75,8 @@ async function _getPlatformProxy() { configPath: runtimeConfig.wrangler.configPath, persist: { path: runtimeConfig.wrangler.persistDir }, }; + // TODO: investigate why + // https://github.com/pi0/nitro-cloudflare-dev/issues/51 if (runtimeConfig.wrangler.environment) { proxyOptions.environment = runtimeConfig.wrangler.environment; } From 4b0ba851ebeb0eed2b9f0603844a42dab1f85182 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Tue, 22 Oct 2024 19:56:05 +0900 Subject: [PATCH 3/6] Update examples/nuxt/nuxt.config.ts --- examples/nuxt/nuxt.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/nuxt/nuxt.config.ts b/examples/nuxt/nuxt.config.ts index 6a99c04..c47b08d 100644 --- a/examples/nuxt/nuxt.config.ts +++ b/examples/nuxt/nuxt.config.ts @@ -1,5 +1,5 @@ // https://nuxt.com/docs/api/configuration/nuxt-config export default defineNuxtConfig({ modules: ["nitro-cloudflare-dev"], - compatibilityDate: "2024-10-10" + compatibilityDate: "2024-10-10", }); From 3cda8139da536b94ccc9f0d059b1ba755f677234 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Tue, 22 Oct 2024 19:56:11 +0900 Subject: [PATCH 4/6] Update examples/nuxt/nuxt.config.ts --- examples/nuxt/nuxt.config.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/nuxt/nuxt.config.ts b/examples/nuxt/nuxt.config.ts index c47b08d..5bfe834 100644 --- a/examples/nuxt/nuxt.config.ts +++ b/examples/nuxt/nuxt.config.ts @@ -3,3 +3,4 @@ export default defineNuxtConfig({ modules: ["nitro-cloudflare-dev"], compatibilityDate: "2024-10-10", }); + From 497756a2565ce7244ec454452942717b1214b23a Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Tue, 22 Oct 2024 19:56:30 +0900 Subject: [PATCH 5/6] Update nuxt.config.ts --- examples/nuxt/nuxt.config.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/nuxt/nuxt.config.ts b/examples/nuxt/nuxt.config.ts index 5bfe834..c47b08d 100644 --- a/examples/nuxt/nuxt.config.ts +++ b/examples/nuxt/nuxt.config.ts @@ -3,4 +3,3 @@ export default defineNuxtConfig({ modules: ["nitro-cloudflare-dev"], compatibilityDate: "2024-10-10", }); - From 3d3ae74c1e9e2b881ee7e4d03cd779e0b4c8d640 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Tue, 22 Oct 2024 19:56:49 +0900 Subject: [PATCH 6/6] Update nuxt.config.ts