Skip to content

Commit

Permalink
fix(dev): prepend baseURL for vite hmr ws upgrade (#370)
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Mar 20, 2024
1 parent a3b2200 commit b6ca41b
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/utils/dev.ts
Expand Up @@ -5,6 +5,7 @@ import chokidar from 'chokidar'
import { consola } from 'consola'
import { debounce } from 'perfect-debounce'
import { toNodeListener } from 'h3'
import { joinURL } from 'ufo'
import {
HTTPSOptions,
ListenURL,
Expand Down Expand Up @@ -244,14 +245,16 @@ class NuxtDevServer extends EventEmitter {
this.listener.server.on(
'upgrade',
async (req: any, socket: any, head: any) => {
if (
req.url.startsWith(
this._currentNuxt?.options.app.buildAssetsDir /* /_nuxt/ */,
)
) {
const nuxt = this._currentNuxt
if (!nuxt) return
const viteHmrPath = joinURL(
nuxt.options.app.baseURL,
nuxt.options.app.buildAssetsDir,
)
if (req.url.startsWith(viteHmrPath)) {
return // Skip for Vite HMR
}
await this._currentNuxt?.server.upgrade(req, socket, head)
await nuxt.server.upgrade(req, socket, head)
},
)
}
Expand Down

0 comments on commit b6ca41b

Please sign in to comment.