Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(wrangler): only set environment if defined #49

Merged
merged 6 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/nuxt/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -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"
pi0 marked this conversation as resolved.
Show resolved Hide resolved
});
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) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some idea: unjs/hookable#105

nitroConfig.modules = nitroConfig.modules || [];
nitroConfig.modules.push(nitroModule);
});
Expand Down
11 changes: 7 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,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) {
pi0 marked this conversation as resolved.
Show resolved Hide resolved
proxyOptions.environment = runtimeConfig.wrangler.environment;
}
const proxy = await getPlatformProxy(proxyOptions);

return proxy;
}
Expand Down
Loading