Skip to content

Commit b39ea5a

Browse files
authored
fix(wrangler): only set environment if defined (#49)
1 parent 37325c2 commit b39ea5a

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

examples/nuxt/nuxt.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
export default defineNuxtConfig({
33
modules: ["nitro-cloudflare-dev"],
44
compatibilityDate: "2024-10-10",
5-
});
5+
});

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ async function nitroModule(nitro: Nitro) {
9090
// Dual compatibility with Nuxt and Nitro Modules
9191
export default function nitroCloudflareDev(arg1: unknown, arg2: unknown) {
9292
if ((arg2 as Nuxt)?.options?.nitro) {
93-
(arg2 as Nuxt).hooks.hook("nitro:config", (nitroConfig) => {
93+
(arg2 as Nuxt).hooks.hookOnce("nitro:config", (nitroConfig) => {
9494
nitroConfig.modules = nitroConfig.modules || [];
9595
nitroConfig.modules.push(nitroModule);
9696
});

src/runtime/plugin.dev.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { NitroAppPlugin } from "nitropack";
2-
import type { PlatformProxy } from "wrangler";
2+
import type { GetPlatformProxyOptions, PlatformProxy } from "wrangler";
33
// @ts-ignore
44
import { useRuntimeConfig, getRequestURL } from "#imports";
55

@@ -71,11 +71,16 @@ async function _getPlatformProxy() {
7171
};
7272
} = useRuntimeConfig();
7373

74-
const proxy = await getPlatformProxy({
74+
const proxyOptions: GetPlatformProxyOptions = {
7575
configPath: runtimeConfig.wrangler.configPath,
7676
persist: { path: runtimeConfig.wrangler.persistDir },
77-
environment: runtimeConfig.wrangler.environment,
78-
});
77+
};
78+
// TODO: investigate why
79+
// https://github.com/pi0/nitro-cloudflare-dev/issues/51
80+
if (runtimeConfig.wrangler.environment) {
81+
proxyOptions.environment = runtimeConfig.wrangler.environment;
82+
}
83+
const proxy = await getPlatformProxy(proxyOptions);
7984

8085
return proxy;
8186
}

0 commit comments

Comments
 (0)