does not work with koa-router@7.0.1
See original GitHub issuekoa-router@7.0.1 is the new koa2 router.
The example for koa-router only works with 5.x. I’ve created an example. If you switch between 7.x and 5.x you can see it will stop working on 7.x
//index.js
require("babel-register");
require("./app.js");
//.babelrc
{
"presets": ["es2015-node5"],
"plugins": [
"transform-async-to-generator",
"syntax-async-functions"
]
}
//app.js
var koa = require('koa');
var websockify = require('koa-websocket');
var router = require('koa-router');
var app = new koa();
var api = router();
var socket = websockify(app);
api.get('/*', function* (next) {
const ctx = this;
ctx.websocket.send('Hello World');
ctx.websocket.on('message', function(message) {
console.log(message);
});
});
app.ws.use(api.routes()).use(api.allowedMethods());
app.listen(3000);
Start with node ./index.js
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
koa-router not working with generator - Stack Overflow
This code works though: var koa = require('koa'); var app = new koa(); var Router = require('koa-router'); var router = new Router(); router....
Read more >ZijianHe/koa-router: Router middleware for koa. - GitHub
Middleware is now always run in the order declared by .use() (or .get() , etc.), which matches Express 4 API. Installation.
Read more >koa-router-groups - npm Package Health Analysis - Snyk
After installing koa-router-groups, all you need to do is extend an existing koa router instance with the extend function.
Read more >koa-router - npm
Middleware is now always run in the order declared by .use() (or .get() , etc.), which matches Express 4 API. Install. npm:.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@kudos any idea?
Thanks to @cymen this is now resolved! Update this to 3.0.1 if you’re running a Koa 2 stack.