refactor: trust
This commit is contained in:
parent
d471e51d6e
commit
17dc2a031c
|
@ -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",
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user