Skip to content

Commit f646d5f

Browse files
committed
wss fix
1 parent 79d9323 commit f646d5f

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

client/src/Hooks/useUpdaterSocket.hook.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import useWebSocket from 'react-use-websocket'
44
import useDebouncedFunction from "./useDebouncedFunction.hook"
55
import { useHttp } from "./http.hook"
66

7-
const WS_PORT = process.env.WS_PORT || 3030
8-
97
/**
108
* Хук веб-сокета обновления данных
119
* @param {void} updateData
@@ -20,10 +18,9 @@ function useUpdaterSocket(updateData, auth) {
2018
/**колбек для получения url сокета */
2119
const getSocketUrl = useCallback(async () => {
2220
return new Promise(resolve => {
23-
request("/getIp")
21+
request("/getSocketAddress")
2422
.then((data) => {
25-
const ip = data.ip
26-
const socketAddress = "ws://" + (ip || "localhost") + ":" + WS_PORT
23+
const socketAddress = data.socketAddress
2724
console.log("socketAddress", socketAddress)
2825
resolve(socketAddress)
2926
})

server/app.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ const app = express()
2222

2323
app.use(express.json({ extended: true }))
2424

25-
app.get('/getIp', (req, res) => {
25+
app.get('/getSocketAddress', (req, res) => {
2626
getIp()
27-
.then((ip) => res.status(200).json({ ip }))
27+
.then((ip) => {
28+
const socketAddress = (httpsRedirect ? "wss" : "ws") + "://" + (ip || "localhost") + ":" + WS_PORT
29+
res.status(200).json({ socketAddress })
30+
})
2831
.catch(() => res.status(500))
2932
})
3033

0 commit comments

Comments
 (0)