CabloyJS V3.2.0支持Socket IO

CabloyJS v3.2.0引入了Socket IO,并且实现了统一的在线推送离线推送机制

效果演示

1. IM

用户向系统发送一条消息,系统通过websocket在线通道向用户推送一条回复

im

2. 进度条

系统通过websocket在线通道向前端实时推送任务的进度

progress

项目配置

升级到该版本,请更新以下项目配置:

1. 增加redis连接信息

请依次修改测试环境开发环境生产环境的配置,这里以开发环境为例

{project}/src/backend/config/config.local.js

  // redis
  ...
  const __redisConnectionDefaultIO = Object.assign({}, __redisConnectionDefault, {
    keyPrefix: `io_${appInfo.name}:`,
  });

  config.redisConnection = {
    ...
    io: __redisConnectionDefaultIO,
  };

  config.redis = {
    clients: {
      redlock: config.redisConnection.default,
      ...
      io: config.redisConnection.io,
    },
  };

2. Nginx配置

在Nginx配置中添加/socket.io/的转向

{project}/docker-compose/config/nginx/conf.d/nginx.conf

  ...
  location /socket.io/ {
    proxy_http_version 1.1;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Host $server_name;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Host $http_host;
    proxy_set_header X-NginX-Proxy true;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_pass http://$node_ip:$node_port$request_uri;
    proxy_redirect off;
    proxy_buffer_size 64k;
    proxy_buffers   4 32k;
    proxy_busy_buffers_size 64k;
  }

你可能感兴趣的:(websocket,node.js,全栈)