UNPKG

381 BJavaScriptView Raw
1import koa from 'koa';
2import router from 'koa-router';
3import websockify from 'koa-websocket';
4
5const app = websockify(koa());
6
7const api = router();
8
9api.get('/*', function* (next) {
10 this.websocket.send('Hello World');
11 this.websocket.on('message', function(message) {
12 console.log(message);
13 });
14});
15
16app.ws.use(api.routes()).use(api.allowedMethods());
17app.listen(3000);