Answer the question
In order to leave comments, you need to log in
How to handle AJAX requests with koa2 and koa-router?
I am using koa-router in a project. I handle requests like this:
const Koa = require('koa'),
router = require('koa-router')(),
body = require('async-busboy'),
app = new Koa();
app.use(router.routes());
app.use(router.allowedMethods());
router.post('/test', async(ctx) => {
const data = await body(ctx.req);
});
const xhr = new XMLHttpRequest();
xhr.open('POST', '/test', true);
xhr.send({one: '12', two: 12});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question