From dcaa9ce0006171f7cbc945ce38ae6d8778286c5b Mon Sep 17 00:00:00 2001 From: hanhh <18330117883@163.com> Date: Wed, 13 Oct 2021 23:09:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dwebsocket=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E5=9F=9F=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/loaders/sock.ts | 2 +- src/layouts/index.tsx | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/back/loaders/sock.ts b/back/loaders/sock.ts index 9393d926..7b05de5c 100644 --- a/back/loaders/sock.ts +++ b/back/loaders/sock.ts @@ -8,7 +8,7 @@ import fs from 'fs'; import { getPlatform } from '../config/util'; export default async ({ server }: { server: Server }) => { - const echo = sockjs.createServer({ prefix: '/ws' }); + const echo = sockjs.createServer({ prefix: '/api/ws' }); const sockService = Container.get(SockService); echo.on('connection', (conn) => { diff --git a/src/layouts/index.tsx b/src/layouts/index.tsx index 0c8968e0..cfd0132d 100644 --- a/src/layouts/index.tsx +++ b/src/layouts/index.tsx @@ -125,13 +125,15 @@ export default function (props: any) { useEffect(() => { ws.current = new SockJS( - `http://127.0.0.1:5600/ws?token=${localStorage.getItem(config.authKey)}`, + `${location.origin}/api/ws?token=${localStorage.getItem(config.authKey)}`, ); - ws.current.onopen = () => { - console.log('ws opened'); + ws.current.onopen = (e) => { + console.log('ws opened', e); }; - ws.current.onclose = () => console.log('ws closed'); + ws.current.onclose = (e) => { + console.log('ws closed', e); + }; const wsCurrent = ws.current; return () => {