Skip to content

Commit fb0f022

Browse files
authored
fix: use listhen's publicUrl if available (#3500)
1 parent c223b9f commit fb0f022

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/runtime/internal/websocket.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { loadDatabaseAdapter } from './database.client'
22
import { useRuntimeConfig, refreshNuxtData } from '#imports'
3+
import { joinURL } from 'ufo'
34

45
const logger = {
56
log: (...args: unknown[]) => console.log('[Content]', ...args),
@@ -79,9 +80,8 @@ export function useContentWebSocket() {
7980
}
8081

8182
// WebSocket Base URL
82-
const wsURL = new URL(`${(useRuntimeConfig().public.content as { wsUrl: string }).wsUrl}ws`)
83+
const wsURL = new URL(joinURL((useRuntimeConfig().public.content as { wsUrl: string }).wsUrl, 'ws'))
8384
wsURL.protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'
84-
wsURL.hostname = window.location.hostname
8585

8686
logger.log(`WS connect to ${wsURL}`)
8787

src/utils/dev.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ export async function startSocketServer(nuxt: Nuxt, options: ModuleOptions, mani
3636
listener = await listen(() => 'Nuxt Content', websocketOptions)
3737

3838
// Register ws url
39-
;(nitro.options.runtimeConfig.public.content as Record<string, unknown>).wsUrl = listener.url.replace('http', 'ws')
39+
const publicConfig = nitro.options.runtimeConfig.public.content as Record<string, unknown>
40+
publicConfig.wsUrl = (websocketOptions.publicURL || listener.url).replace('http', 'ws')
4041

4142
listener.server.on('upgrade', websocket.serve)
4243
})

0 commit comments

Comments
 (0)