Browse Source

Fix: socket does not handle server.path option

Tran Van Sang 6 years ago
parent
commit
65c127cf7c
1 changed files with 4 additions and 2 deletions
  1. 4 2
      packages/@uppy/companion/src/uppy.js

+ 4 - 2
packages/@uppy/companion/src/uppy.js

@@ -105,7 +105,7 @@ module.exports.app = (options = {}) => {
  *
  * @param {object} server
  */
-module.exports.socket = (server) => {
+module.exports.socket = (server, option) => {
   const wss = new SocketServer({ server })
   const redisClient = redis.client()
 
@@ -114,7 +114,9 @@ module.exports.socket = (server) => {
   // client attempts to reconnect.
   wss.on('connection', (ws) => {
     // @ts-ignore
-    const fullPath = ws.upgradeReq.url
+    let fullPath = ws.upgradeReq.url
+    if (option && option.server && option.server.path && fullPath.startsWith(option.server.path))
+      fullPath = fullPath.slice(option.server.path.length)
     // the token identifies which ongoing upload's progress, the socket
     // connection wishes to listen to.
     const token = fullPath.replace(/\/api\//, '')