Skip to content

Commit

Permalink
fix(wrangler): only set environment if defined (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
atinux authored Oct 22, 2024
1 parent 37325c2 commit b39ea5a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/nuxt/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
export default defineNuxtConfig({
modules: ["nitro-cloudflare-dev"],
compatibilityDate: "2024-10-10",
});
});
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
13 changes: 9 additions & 4 deletions src/runtime/plugin.dev.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit b39ea5a

Please sign in to comment.