Skip to content

Commit

Permalink
fix: handling of host and origin. Updated to support new query system
Browse files Browse the repository at this point in the history
  • Loading branch information
frankpagan committed Jan 13, 2024
1 parent aaa7f94 commit 61a1c68
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ class SocketServer extends EventEmitter {
socket.destroy();
});

server.https.on('upgrade', (request, socket, head) => this.upgrade(request, socket, head))
server.http.on('upgrade', (request, socket, head) => this.upgrade(request, socket, head))
server.https.on('upgrade', (request, socket, head) => this.upgrade(request, socket, head, 'wss'))
server.http.on('upgrade', (request, socket, head) => this.upgrade(request, socket, head, 'ws'))
}

upgrade(request, socket, head) {
upgrade(request, socket, head, protocol) {
const self = this;
let organization_id = request.url.split('/')
organization_id = organization_id[organization_id.length - 1]
Expand All @@ -53,20 +53,19 @@ class SocketServer extends EventEmitter {
socket.id = options.socketId;
socket.clientId = options.clientId;
socket.pathname = request.url
socket.origin = request.headers.origin || request.headers.host
socket.origin = request.headers.origin
socket.host = request.headers.host

if (socket.origin.startsWith('http'))
socket.origin = socket.origin.replace('http', 'ws')

socket.socketUrl = socket.origin + socket.pathname

if (socket.origin && socket.origin !== 'null') {
if (!socket.host && socket.origin && socket.origin !== 'null') {
if (socket.origin.includes('://'))
socket.host = new URL(socket.origin).host
else
socket.host = socket.origin;
}

socket.socketUrl = protocol + '://' + socket.host + socket.pathname


// if (!await server.acme.checkCertificate(socket.host, organization_id))
// return socket.send(JSON.stringify({ method: 'Access Denied', error: 'Host not whitelisted' }))

Expand All @@ -85,9 +84,10 @@ class SocketServer extends EventEmitter {
}

if (options.lastSynced)
data.$filter.query = [
{ key: '_id', value: options.lastSynced, operator: '$gt' }
]
data.$filter.query = {
_id: { $gt: options.lastSynced }
}

else
data.$filter.limit = 1

Expand Down

0 comments on commit 61a1c68

Please sign in to comment.