Skip to content
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: 2 additions & 2 deletions src/runtime/internal/websocket.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { loadDatabaseAdapter } from './database.client'
import { useRuntimeConfig, refreshNuxtData } from '#imports'
import { joinURL } from 'ufo'

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

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

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

Expand Down
3 changes: 2 additions & 1 deletion src/utils/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export async function startSocketServer(nuxt: Nuxt, options: ModuleOptions, mani
listener = await listen(() => 'Nuxt Content', websocketOptions)

// Register ws url
;(nitro.options.runtimeConfig.public.content as Record<string, unknown>).wsUrl = listener.url.replace('http', 'ws')
const publicConfig = nitro.options.runtimeConfig.public.content as Record<string, unknown>
publicConfig.wsUrl = (websocketOptions.publicURL || listener.url).replace('http', 'ws')
Copy link
Contributor

Choose a reason for hiding this comment

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

publicConfig.wsUrl = (websocketOptions.publicURL || process.env.publicURL || listener.url).replace('http', 'ws')

to use option --publicURL defined by the nuxt dev command.

Copy link
Member Author

Choose a reason for hiding this comment

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

Have you tries this?
Public URL of websocket and Nuxt are different, since the module creates its own server for websocket, using same publicURL will cause issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

It’s actually only the port that is different, not the public URL.

Copy link
Member Author

@farnabaz farnabaz Sep 1, 2025

Choose a reason for hiding this comment

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

It’s actually only the port that is different, not the public URL.

We are passing the whole url to client and we don't change the port. So sharing same url means calling to the same port.

We can do it by adding port to publicUrl in publicConfig.wsUrl = (websocketOptions.publicURL || listener.url).replace('http', 'ws') but the end result will not be same.


listener.server.on('upgrade', websocket.serve)
})
Expand Down
Loading