title: WebSockets on specific route in Nest.js
body: <p>I'd like to create specific API route which will be used only WebSocket (<code>/api/events</code>) but in all examples of implementing WebSockets on Nest.js I stumbled upon module is imported in <code>AppModule</code> and client is emitting events toward the root URL, which I can't do because I have this middleware;</p>
  
  <p><strong>frontend.middleware.ts</strong></p>
  
  <pre><code>import { Request, Response } from 'express';
  import { AppModule } from '../../app.module';
  
  export function FrontendMiddleware(
    req: Request,
    res: Response,
    next: Function,
  ) {
    const { baseUrl } = req;
    if (baseUrl.indexOf('/api') === 0) {
      next();
    } else {
      res.sendFile('index.html', { root: AppModule.getStaticAssetsRootPath() });
    }
  }
  </code></pre>
  
  <p>Here is the <code>EventGateway</code> and <code>EventModule</code>:</p>
  
  <p><strong>event.gateway.ts</strong></p>
  
  <pre><code>import {
    SubscribeMessage,
    WebSocketGateway,
    WebSocketServer,
    WsResponse,
  } from '@nestjs/websockets';
  import { from, Observable } from 'rxjs';
  import { map } from 'rxjs/operators';
  import { Client, Server } from 'socket.io';
  
  @WebSocketGateway({ namespace: 'events' })
  export class EventGateway {
    @WebSocketServer()
    server: Server;
  
    @SubscribeMessage('events')
    findAll(client: Client, data: any): Observable&lt;WsResponse&lt;number&gt;&gt; {
      return from([1, 2, 3]).pipe(map(item =&gt; ({ event: 'events', data: item })));
    }
  
    @SubscribeMessage('identity')
    async identity(client: Client, data: number): Promise&lt;number&gt; {
      return data;
    }
  }
  </code></pre>
  
  <p><strong>event.module.ts</strong></p>
  
  <pre><code>import { Module } from '@nestjs/common';
  import { EventGateway } from './event.gateway';
  
  @Module({
    components: [EventGateway],
  })
  export class EventModule {}
  </code></pre>
  
  <p>Is there a way to create controller which will allow server-client communication via <code>/api/events</code>?</p>