refactor: trust

This commit is contained in:
cha0s 2020-12-13 06:02:21 -06:00
parent d471e51d6e
commit 17dc2a031c
2 changed files with 2 additions and 5 deletions

View File

@ -27,7 +27,6 @@
"@latus/react": "^1.0.0",
"buffer": "^6.0.3",
"debug": "4.3.1",
"express": "^4.17.1",
"proxy-addr": "^2.0.6",
"schemapack": "^1.4.2",
"socket.io": "2.3.0",

View File

@ -1,4 +1,3 @@
import {compileTrust} from 'express/lib/utils';
import proxyaddr from 'proxy-addr';
import SocketIoServer from 'socket.io';
@ -8,7 +7,6 @@ import SocketIoParser from './packet/socket.io-parser';
export default class SocketServer {
constructor(httpServer, latus) {
const {config: {'@latus/http': {trust}}} = latus;
// eslint-disable-next-line no-param-reassign
latus.config['%sockets'] = this;
this.onConnect = this.onConnect.bind(this);
@ -27,7 +25,7 @@ export default class SocketServer {
});
latus.invoke('@latus/socket/server.io', this.io);
this.io.on('connect', this.onConnect);
const trustFn = compileTrust(trust);
const {app} = httpServer;
this.io.use((socket, next) => {
Object.defineProperty(socket.handshake, 'ip', {
configurable: true,
@ -35,7 +33,7 @@ export default class SocketServer {
get: () => proxyaddr({
connection: socket.conn,
headers: socket.request.headers,
}, trustFn),
}, app.get('trust proxy fn')),
});
latus.invokeMiddleware('@latus/socket/authenticate', socket, next);
});