koajs / bodyparser

Koa body parsing middleware
MIT License
1.31k stars 117 forks source link

Usage with Windows10 #53

Closed SengitU closed 8 years ago

SengitU commented 8 years ago

Hello all,

I am trying to using bodyparser with next flag. Everything seems fine until I send a POST request. The body seems to be empty all the time. I investigated the issue and came up with incompatible dependency with Windows10. koa-bodyparser

Is there a workaround to by-pass this problem?

Thanks! Uğurcan

dead-horse commented 8 years ago

koa-bodyparser and it's dependencies don't dependent on it, and fsevents here is an optional dependency, it won't affect koa-bodyparser.

can you present your request headers and body?

SengitU commented 8 years ago

Hello @dead-horse ,

Thanks for you help, I will provide information about my setup and request.

I send POST request from Postman extension. Request body as follows as JSON;

{
  "startDate":"2016-08-03T13:25:53.153Z",
  "email":"logintest@example.com",
  "password":"123",
  "name":"efsdf",
  "surname":"sdfsdf",
  "birthDate":"03/08/2016",
  "company":"dsfsd",
  "position":"sdfsdf",
  "registerDate":"2016-08-03T13:25:53.153Z",
  "lastLoginDate":"2016-08-03T13:25:53.153Z"
}

and I have Accept: application/json header

Code snippet I use;

router.post('/', async(context, next) => {
  try {
    console.log(context.request);
    context.body = await post(context.request.body);
    await next();
  } catch (err) {
    console.log(err);
    context.throw(500);
  }
});

My koa dependencies;

"koa": "^2.0.0-alpha.4",
"koa-bodyparser": "^3.2.0",
"koa-logger": "^1.3.0",
"koa-router": "^7.0.1"

context.request is as follows logged in console;

{
    method: 'POST',
    url: '/api/auth/register',
    header: {
        host: 'localhost:3000',
        connection: 'keep-alive',
        'content-length': '309',
        accept: 'application/json',
        'cache-control': 'no-cache',
        origin: 'chrome-extension://fdmmgilgnpjigdojojpjoooidkmcomcm',
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36',
        'content-type': 'text/plain;charset=UTF-8',
        'accept-encoding': 'gzip, deflate',
        'accept-language': 'tr,en-US;q=0.8,en;q=0.6,zh-CN;q=0.4,zh;q=0.2,zh-TW;q=0.2,fr;q=0.2'
    }
}
$ node -v
v6.3.1
$ npm -v
3.10.5

My problem here is that, context.request.body is always empty object. Please note that, my friend run this code just fine in Mac.

Regards, Uğurcan

SengitU commented 8 years ago

I have just recognized that, adding Content-Type: application/json resolved my issue.

I will close the issue, thanks for your help!