question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

does not work with koa-router@7.0.1

See original GitHub issue

koa-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:closed
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
anthonyettingercommented, Aug 11, 2016

@kudos any idea?

0reactions
kudoscommented, Oct 1, 2016

Thanks to @cymen this is now resolved! Update this to 3.0.1 if you’re running a Koa 2 stack.

Read more comments on GitHub >

github_iconTop 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 | Yarn - Package Manager
Fast, reliable, and secure dependency management.
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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found