ServerTransportBun WebSockets

Bun WebSockets

Colyseus supports Bun’s native WebSockets implementation through the @colyseus/bun-websockets package. This transport layer is designed to be used with Bun’s built-in HTTP server, and it also provides an Express compatibility layer for easier integration with existing codebases.

⚠️

Bun support on Colyseus is still experimental. Please report any issues you may find.

Installation

Terminal
bun add @colyseus/bun-websockets
app.config.ts
import { defineServer } from "colyseus";
import { BunWebSockets } from "@colyseus/bun-websockets"
 
const server = defineServer({
  // ...
  transport: new BunWebSockets({
    /* Bun.serve options */
  }),
 
  //
  // BunWebSockets comes with Express compatibility layer.
  //
  express: (app) => {
    // register routes
    app.get("/hello", (req, res) => {
      res.json({ hello: "world!" });
    });
  },
  // ...
});