From 1059c58cc025d8489cdff713856ec57a40613047 Mon Sep 17 00:00:00 2001 From: Adriana Trif Date: Mon, 22 Nov 2021 20:52:18 +0200 Subject: [PATCH] Add basePath to ws url --- packages/dev-server-core/src/server/addPlugins.ts | 2 +- packages/dev-server-core/src/web-sockets/webSocketsPlugin.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/dev-server-core/src/server/addPlugins.ts b/packages/dev-server-core/src/server/addPlugins.ts index d579cfc0c..34a5af51a 100644 --- a/packages/dev-server-core/src/server/addPlugins.ts +++ b/packages/dev-server-core/src/server/addPlugins.ts @@ -14,7 +14,7 @@ export function addPlugins(logger: Logger, config: DevServerCoreConfig) { } if (config.injectWebSocket && config.plugins?.some(pl => pl.injectWebSocket)) { - config.plugins.unshift(webSocketsPlugin()); + config.plugins.unshift(webSocketsPlugin(config.basePath)); } if (config.plugins?.some(pl => 'resolveImport' in pl || 'transformImport' in pl)) { diff --git a/packages/dev-server-core/src/web-sockets/webSocketsPlugin.ts b/packages/dev-server-core/src/web-sockets/webSocketsPlugin.ts index 6dc5b3cda..0850106ac 100644 --- a/packages/dev-server-core/src/web-sockets/webSocketsPlugin.ts +++ b/packages/dev-server-core/src/web-sockets/webSocketsPlugin.ts @@ -5,7 +5,7 @@ import { appendToDocument, isHtmlFragment } from '@web/parse5-utils'; export const webSocketScript = ` `; -export function webSocketsPlugin(): Plugin { +export function webSocketsPlugin(basePath?: string): Plugin { return { name: 'web-sockets', @@ -128,7 +128,7 @@ export function webSocketsPlugin(): Plugin { const { protocol, host } = new URL(import.meta.url); -const webSocketUrl = \`ws\${protocol === 'https:' ? 's' : ''}://\${host}/${NAME_WEB_SOCKET_API}\`; +const webSocketUrl = \`ws\${protocol === 'https:' ? 's' : ''}://\${host}/${basePath ? basePath + '/' : ''}${NAME_WEB_SOCKET_API}\`; export let webSocket; export let webSocketOpened;