我有一个 Nestjs 网关,我试图根据标头中的值运行授权逻辑,但无论我试图访问握手,它总是返回“未定义”
我也在通过 SSL 尝试这个,这可能会有所作为。
main.ts:
import { WsAdapter } from "@nestjs/platform-ws";
app = await NestFactory.create(UserMicroserviceModule, {
httpsOptions: {
key: get_ssl("key"),
cert: get_ssl("cert"),
},
});
app.useWebSocketAdapter(new WsAdapter(app));
await app.listen(process.env.PORT || 443);
网关.ts:
@UseGuards(SessionGuard)
@WebSocketGateway({ path: "/user" })
export class UserMicroserviceGateway implements OnGatewayConnection {
handleConnection(socket) {
socket.handshake // <== undefined
}
session.guard.ts:
const socket_cookie: any = context.switchToWs().getClient().handshake; // <== undefined
而且,虽然我已经在整个网关上添加了会话保护 --- 保护不会触发 handleConnection()