inversify-restify-utils一个空的上下文和控制器中的一个主体

inversify-restify-utils an empty context and a body 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?

I misconfigured server. I was needed to add setConfig() while creating the app:

//create restify application
this.app = new InversifyRestifyServer(container, {
  name: AppConstants.APP_NAME,
  version: nconf.get("server:api_version"),
  log: this.logger
}).setConfig((app) => {
  this.config(app); // configure app
}).build();

Example of the config.

public config(app) {
    // configure cors
    app.use(restify.CORS({
      origins: nconf.get("server:origins"),   // defaults to ['*']
      credentials: false,                 // defaults to false
    }));

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

    setupPassport(passport);

    app.post('/test', (req, res, next) => {
      console.log(req.body);
      res.json(new Response(true, 'ok'));
      next();
    });

    // start listening
    app.listen(this.getPort(), this.getHost(), () => {
      log(`${app.name} listening at ${app.url}`);
    });
    // error handler
    app.on('error', (error) => {
      this.onError(error);
    });
    // process exceptions
    app.on('uncaughtException', function (request, response, route, error) {
      console.error(error.stack);
      response.send(error);
    });
    // audit logger
    app.on('after', restify.auditLogger({
      log: this.logger
    }));
  }