diff --git a/docs/content/3.api/5.commands/dev.md b/docs/content/3.api/5.commands/dev.md index ef603dbbc8..06d550f6d8 100644 --- a/docs/content/3.api/5.commands/dev.md +++ b/docs/content/3.api/5.commands/dev.md @@ -25,3 +25,7 @@ This command sets `process.env.NODE_ENV` to `development`. ::alert{type="info"} If you are using a self-signed certificate in development, you will need to set `NODE_TLS_REJECT_UNAUTHORIZED=0` in your environment. :: + +::stabilityEdge{title="Improved HTTPS Support"} +With next releases, `NODE_TLS_REJECT_UNAUTHORIZED` is no longer required. You can try this on edge channel using `npx nuxi-edge@latest dev --https` +:: diff --git a/packages/vite/src/runtime/client.manifest.mjs b/packages/vite/src/runtime/client.manifest.mjs index f33e3b2a79..a30f394960 100644 --- a/packages/vite/src/runtime/client.manifest.mjs +++ b/packages/vite/src/runtime/client.manifest.mjs @@ -1,6 +1,3 @@ -import { $fetch } from 'ohmyfetch' -import { getViteNodeOptions } from './vite-node-shared.mjs' +import { viteNodeFetch } from './vite-node-shared.mjs' -const viteNodeOptions = getViteNodeOptions() - -export default () => $fetch('/manifest', { baseURL: viteNodeOptions.baseURL }) +export default () => viteNodeFetch('/manifest') diff --git a/packages/vite/src/runtime/vite-node-shared.mjs b/packages/vite/src/runtime/vite-node-shared.mjs index 509063e6c6..ebe6fe4501 100644 --- a/packages/vite/src/runtime/vite-node-shared.mjs +++ b/packages/vite/src/runtime/vite-node-shared.mjs @@ -1,3 +1,11 @@ -export function getViteNodeOptions () { - return JSON.parse(process.env.NUXT_VITE_NODE_OPTIONS || '{}') -} +import { Agent as HTTPSAgent } from 'node:https' +import { $fetch } from 'ohmyfetch' + +export const viteNodeOptions = JSON.parse(process.env.NUXT_VITE_NODE_OPTIONS || '{}') + +export const viteNodeFetch = $fetch.create({ + baseURL: viteNodeOptions.baseURL, + agent: viteNodeOptions.baseURL.startsWith('https://') + ? new HTTPSAgent({ rejectUnauthorized: false }) + : null +}) diff --git a/packages/vite/src/runtime/vite-node.mjs b/packages/vite/src/runtime/vite-node.mjs index dab7b3d5a1..0784d29d8a 100644 --- a/packages/vite/src/runtime/vite-node.mjs +++ b/packages/vite/src/runtime/vite-node.mjs @@ -1,11 +1,9 @@ import { performance } from 'node:perf_hooks' import { createError } from 'h3' import { ViteNodeRunner } from 'vite-node/client' -import { $fetch } from 'ohmyfetch' import consola from 'consola' -import { getViteNodeOptions } from './vite-node-shared.mjs' +import { viteNodeOptions, viteNodeFetch } from './vite-node-shared.mjs' -const viteNodeOptions = getViteNodeOptions() const runner = createRunner() let render @@ -15,9 +13,7 @@ export default async (ssrContext) => { process.server = true // Invalidate cache for files changed since last rendering - const invalidates = await $fetch('/invalidates', { - baseURL: viteNodeOptions.baseURL - }) + const invalidates = await viteNodeFetch('/invalidates') const updates = runner.moduleCache.invalidateDepTree(invalidates) // Execute SSR bundle on demand @@ -39,9 +35,7 @@ function createRunner () { async fetchModule (id) { // TODO: fix in vite-node id = id.replace(/\/\//g, '/') - return await $fetch('/module/' + encodeURI(id), { - baseURL: viteNodeOptions.baseURL - }).catch((err) => { + return await viteNodeFetch('/module/' + encodeURI(id)).catch((err) => { const errorData = err?.data?.data if (!errorData) { throw err