I want to integrate colyseus with nestjs by one instance. please help suggest solution for me.
How to integrate colyseus with nestjs
Hi @b-thanapat, welcome! 👋
I've just managed to get NestJS (7.6.15) + Colyseus (0.14.x) working together by doing this:
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { Room, Server } from "colyseus";
import { MyRoom } from "./MyRoom";
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const gameServer = new Server();
gameServer.define("my_room", MyRoom);
// attach Colyseus into the existing http server from NestJS
gameServer.attach({ server: app.getHttpServer() });
await app.listen(2567);
}
bootstrap();
Hope this helps, cheers!