Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

fix(vite): nuxi dev --https working out of the box #7547

Merged
merged 5 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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: 4 additions & 0 deletions docs/content/3.api/5.commands/dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
::
7 changes: 2 additions & 5 deletions packages/vite/src/runtime/client.manifest.mjs
Original file line number Diff line number Diff line change
@@ -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')
14 changes: 11 additions & 3 deletions packages/vite/src/runtime/vite-node-shared.mjs
Original file line number Diff line number Diff line change
@@ -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
})
12 changes: 3 additions & 9 deletions packages/vite/src/runtime/vite-node.mjs
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down