Tuesday, 23 May 2017

inversify-restify-utils an empty context in the controller

I try to get working inversify-restify-utils but I faced with a problem. Request context and body variable are empty. My controller:

@Controller('/users')
@injectable()
export class UsersController implements interfaces.Controller {

  @Post('/')
  createUser(req: restify.Request, res: restify.Response, next: restify.Next) {
    console.log(req.body); // undefined
  }
}

My server.ts:

// to get query params in req.query
this.server.use(restify.acceptParser(this.server.acceptable));
// to get passed json in req.body
this.server.use(restify.bodyParser());

this.server.post('/test', (req, res, next) => {
  console.log(req.body); // ok
  next();
});

Any suggestions?



via Alex Po

No comments:

Post a Comment