M
M
Michael2016-11-14 16:50:21
Node.js
Michael, 2016-11-14 16:50:21

What is the correct way to use koa-route for koa 2.x?

I'm trying to do it like this:

const Koa = require('koa'),
      router = require('koa-router')(),
      app = new Koa();

 router.get('/hello', async (ctx, next) => {
   ctx.body = 'it is working!';
});

But no reaction. Already tried everything. Does not work. Where is the mistake?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton, 2016-11-14
@SPAHI4

the very first example from the official documentation

var app = require('koa')();
var router = require('koa-router')();

router.get('/', function (ctx, next) {...});

app
  .use(router.routes())
  .use(router.allowedMethods());

+ mb you have an old version of the router
npm install [email protected]

D
Dmitry Serkov, 2017-02-10
@Hutaab

I decided: there was a jamb in the etc/lightdm/lightdm.conf file (it was my own fault), I corrected it,
everything worked.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question