移动 中间件声明顺序

This commit is contained in:
Suwings 2021-07-16 15:32:45 +08:00
parent 35d02ad076
commit b78e4e1a21

View File

@ -1,7 +1,7 @@
/*
* @Author: Copyright(c) 2020 Suwings
* @Date: 2020-11-23 17:45:02
* @LastEditTime: 2021-07-15 15:45:42
* @LastEditTime: 2021-07-16 15:28:47
* @Description: Route navigator, used to analyze the Socket.io protocol and encapsulate and forward to a custom route
* @Projcet: MCSManager Daemon
* @License: MIT
@ -51,14 +51,6 @@ export const routerApp = new RouterApp();
export function navigation(socket: Socket) {
// Full-life session variables (Between connection and disconnection)
const session: any = {};
// Register all events with Socket
for (const event of routerApp.eventNames()) {
socket.on(event, (protocol: IPacket) => {
if (!protocol) return logger.info(`session $(socket.id) request data protocol format is incorrect`);
const ctx = new RouterContext(protocol.uuid, socket, session, event.toString());
routerApp.emitRouter(event as string, ctx, protocol.data);
});
}
// Register all middleware with Socket
for (const fn of routerApp.getMiddlewares()) {
socket.use((packet, next) => {
@ -68,6 +60,15 @@ export function navigation(socket: Socket) {
fn(packet[0], ctx, protocol.data, next);
});
}
// Register all events with Socket
for (const event of routerApp.eventNames()) {
socket.on(event, (protocol: IPacket) => {
if (!protocol) return logger.info(`session $(socket.id) request data protocol format is incorrect`);
const ctx = new RouterContext(protocol.uuid, socket, session, event.toString());
routerApp.emitRouter(event as string, ctx, protocol.data);
});
}
}
logger.info("Loading routing controller and middleware...");