From 25ec4d4a844d76b2826974e96697c2bcecb16900 Mon Sep 17 00:00:00 2001 From: nemanjan00 Date: Fri, 27 Sep 2019 23:54:23 +0200 Subject: [PATCH] Make it work with route array --- src/add-ws-method.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/add-ws-method.js b/src/add-ws-method.js index 8c3a279..9b51c78 100644 --- a/src/add-ws-method.js +++ b/src/add-ws-method.js @@ -5,6 +5,15 @@ export default function addWsMethod(target) { /* This prevents conflict with other things setting `.ws`. */ if (target.ws === null || target.ws === undefined) { target.ws = function addWsRoute(route, ...middlewares) { + // In case you are using app.ws(["/a", "/b"], ...middlewares) like it works in express, we map ws to all routes + if(route instanceof Array) { + const routes = route.map(route => { + return target.ws(route, ...middlewares); + }); + + return routes[0]; + } + const wrappedMiddlewares = middlewares.map(wrapMiddleware); /* We append `/.websocket` to the route path here. Why? To prevent conflicts when