1

我正在尝试将“事件”模块添加到我的应用程序以使用 websockets,但是当我添加模块时,我收到以下错误:

(node:59905) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Request mapping properties not defined in the @RequestMapping() annotation!
(node:59905) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

所有其他模块均已成功加载和映射,并且仅在我添加 EventsModule 时发生

所以这是我的代码:

app.module.ts

@Module({
    modules: [AuthModule, DatabaseModule, UsersModule, TimespansModule, LogsModule, EntitiesModule, EventsModule]
})

events.module.ts

import {EventsComponent} from './events.component';
import {Module} from '@nestjs/common';
@Module({
    controllers: [EventsComponent]
})
export class EventsModule {}

events.component.ts

import {WebSocketGateway, SubscribeMessage, OnGatewayConnection} from '@nestjs/websockets';

@WebSocketGateway({namespace: 'events'})
export class EventsComponent implements OnGatewayConnection {
    handleConnection(client: any) {
        console.log('client connected');
    }

    @SubscribeMessage('stream-received')
    onStream(client, data) {
        console.log('stream received');
    }
}

我真的看不出这里出了什么问题,错误消息也对我没有多大帮助。

4

1 回答 1

0

在 events.module.ts 中发现问题

import {EventsComponent} from './events.component';
import {Module} from '@nestjs/common';    
@Module({
    controllers: [EventsComponent]
})
export class EventsModule {}

必须更改控制器 => 组件

import {EventsComponent} from './events.component';
import {Module} from '@nestjs/common';    
@Module({
    components: [EventsComponent]
})
export class EventsModule {}
于 2017-12-06T13:33:44.013 回答