优化socket.js
This commit is contained in:
parent
b59f4069ca
commit
fc82a4ef09
@ -5,17 +5,8 @@ import { getCachedResource, getCachedListResource } from 'jingrow-ui';
|
|||||||
export function initSocket() {
|
export function initSocket() {
|
||||||
let host = window.location.hostname;
|
let host = window.location.hostname;
|
||||||
let siteName = window.site_name;
|
let siteName = window.site_name;
|
||||||
let protocol = window.location.protocol.slice(0, -1); // 移除末尾的 ':'
|
let protocol = window.location.protocol.slice(0, -1);
|
||||||
|
let port = window.location.port ? `:${socketio_port}` : '';
|
||||||
// 开发模式:使用 socketio_port(有端口或明确是开发环境)
|
|
||||||
// 生产模式:使用当前页面的协议和域名,不指定端口(通过 nginx 反向代理)
|
|
||||||
let port = '';
|
|
||||||
if (window.location.port) {
|
|
||||||
// 开发模式或有明确端口,使用 socketio_port
|
|
||||||
port = `:${socketio_port}`;
|
|
||||||
}
|
|
||||||
// 生产模式(HTTPS 443 或 HTTP 80):不指定端口,使用当前页面的协议和域名
|
|
||||||
|
|
||||||
let url = `${protocol}://${host}${port}/${siteName}`;
|
let url = `${protocol}://${host}${port}/${siteName}`;
|
||||||
|
|
||||||
let socket = io(url, {
|
let socket = io(url, {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user