Skip to content

Commit 4a2ff7d

Browse files
committed
making faye-websocket an optional dependency
1 parent cf5cdb4 commit 4a2ff7d

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

index.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,19 @@ const gateway = (opts) => {
3535
})
3636

3737
// processing websocket routes
38-
registerWebSocketRoutes({
39-
routes: opts.routes.filter(route => route.proxyType === 'websocket'),
40-
server: router.getServer()
41-
})
38+
const wsRoutes = opts.routes.filter(route => route.proxyType === 'websocket')
39+
if (wsRoutes.length) {
40+
if (typeof router.getServer !== 'function') {
41+
throw new Error(
42+
'Unable to retrieve the HTTP server instance. ' +
43+
'If you are not using restana, make sure to provide an "app.getServer()" alternative method!'
44+
)
45+
}
46+
registerWebSocketRoutes({
47+
routes: wsRoutes,
48+
server: router.getServer()
49+
})
50+
}
4251

4352
// processing non-websocket routes
4453
opts.routes.filter(route => route.proxyType !== 'websocket').forEach(route => {

lib/ws-proxy.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
'use strict'
22

3-
const WebSocket = require('faye-websocket')
43
const { onOpenNoOp } = require('./default-hooks').websocket
54

65
module.exports = (config) => {
6+
const WebSocket = require('faye-websocket')
7+
78
const { routes, server } = config
89

910
const prefix2route = new Map()

0 commit comments

Comments
 (0)