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