colyseus / uWebSockets-express

Express API compatibility layer for uWebSockets.js
https://npmjs.com/package/uwebsockets-express
MIT License
56 stars 13 forks source link

Cannot use uWebSockets-express with @colyseus/monitor #19

Closed wizigon closed 2 years ago

wizigon commented 2 years ago

I followed alternative-express-compatibility-layer to employ uWebSockets.js in my Colyseus server. I tried to enable the monitoring module by the following code snippet but it failed:

const uwsTransport = new uWebSocketsTransport({});
const app = expressify(uwsTransport.app);

app.use(cors());
app.use(express.json());

const auth = basicAuth.default({
  users: {
    user: "password",
  },
  challenge: true,
});
app.use(auth);
app.use("/colyseus", monitor());

const gameServer = new Server({
  transport: new uWebSocketsTransport({}),
});

Querying to some-domain/colyseus/api just returned me with blank content.

What am I doing wrong with this code snippet?

endel commented 2 years ago

Hi @wizigon, you're instantianting uWebSocketsTransport twice.

You should use the same instance created in the first place:

const gameServer = new Server({ 
  transport: uwsTransport
});