Testing koa.js and fetch on the client side. I am trying to post some data on the server. I am getting undefined with the code below. I am unsure why.
I have inspected this
, this.request
, this.req
, etc and I cannot find my data from the client req?
Server
import koaRouter from 'koa-router'
// Post route
router.post('/api/upload', function *(next) {
console.log('UPLOAD WORKS', this.req.body)
this.status = 200
})
app
.use(bodyParser())
.use(router.routes())
.use(router.allowedMethods())
The console gives me undefined.
Client
fetch('/api/upload', {
method: 'post',
body: 'Hello'
}).then(function(response) {
console.log(response)
}).catch(function(err) {
// Error :(
});