Skip to content

Commit

Permalink
Updated dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
b3nsn0w committed Jun 6, 2019
1 parent cb03c08 commit e3d6187
Show file tree
Hide file tree
Showing 7 changed files with 238 additions and 236 deletions.
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ const WebSocket = require('ws')

const manualPromise = () => {
let result
const promise = new Promise((resolve, reject) => (result = {resolve, reject}))
return {...result, promise}
const promise = new Promise((resolve, reject) => (result = { resolve, reject }))
return { ...result, promise }
}

const serversPatched = new WeakSet()

function createWebsocketMiddleware (propertyName = 'ws', options) {
if (!options) options = {}
if (options instanceof http.Server) options = {server: options}
if (options instanceof http.Server) options = { server: options }

if (parseInt(process.versions.node) < 10 && !options.noServerWorkaround) { // node 9 or earlier needs a workaround for upgrade requests
if (!options.server) {
Expand All @@ -31,7 +31,7 @@ function createWebsocketMiddleware (propertyName = 'ws', options) {
}

debug(`websocket middleware created with property name '${propertyName}'`)
const wss = new WebSocket.Server({noServer: true})
const wss = new WebSocket.Server({ noServer: true })

const websocketMiddleware = async (ctx, next) => {
debug(`websocket middleware called on route ${ctx.path}`)
Expand All @@ -40,7 +40,7 @@ function createWebsocketMiddleware (propertyName = 'ws', options) {
if (~upgradeHeader.indexOf('websocket')) {
debug(`websocket middleware in use on route ${ctx.path}`)
ctx[propertyName] = async () => {
const {promise, resolve} = manualPromise()
const { promise, resolve } = manualPromise()
wss.handleUpgrade(ctx.req, ctx.request.socket, Buffer.alloc(0), resolve)
ctx.respond = false

Expand Down
Loading

0 comments on commit e3d6187

Please sign in to comment.