0

我有一个现有的 KOA 服务器,并希望将 uWebSockets.js 用于其中的一部分(如聊天功能和其他类型的直接通知)

我看到 uWebSockets.js 可以作为独立服务器运行,但是将整个 KOA 服务器重新设计为 uWebSockets.js 就太过分了。这就是为什么我只想将 uWebSockets 放在我的 http API 旁边,或者只是替换继续使用 ctx 对象和 koa 特定内容的 http 部分:

const app = new Koa();

// ...here is some logic, DB init etc

// Here are my routes https://myapi.com/login https://myapi.com/getUser etc...
app.use(routers.routes());
app.use(routers.allowedMethods());

// IT would be nice to place the websocket somewhere here if possible, and to use some route like https://myapi.com/ws In best case it would reuse the existing DB connections etc...

const port = process.env.PORT || 3000;

app.listen(port, () => {
  console.log(`Server running on port ${port}`);
});
4

0 回答 0