在Heroku上运行Swagger:端口问题?

时间:2016-01-28 11:34:56

标签: node.js heroku server swagger

我正在使用nodeJS,express,swagger-tools来获取来自我的Heroku dyno中的/ docs的Swagger API文档。在本地,这是有效的,但在Heroku上,端口没有收听。

app[web.1]: info: Swagger-ui is available on localhost:5765/docs
heroku[web.1]: State changed from crashed to starting
heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
heroku[web.1]: Stopping process with SIGKILL
heroku[web.1]: Process exited with status 137

在代码上,我有Heroku预定的端口。

var listen_addr = 'localhost';
var listen_port = process.env.PORT || 8080;

var swaggerDoc = require(options.swaggerUi);
swaggerDoc.host = listen_addr +":" + listen_port;    // making sure of add

swaggerTools.initializeMiddleware(swaggerDoc, function (middleware) {

  app.use(middleware.swaggerMetadata());
  app.use(middleware.swaggerValidator());           
  app.use(middleware.swaggerUi() );             
  app.use(middleware.swaggerRouter(options) );

  app.listen(listen_port, listen_addr) {      
    winston.info('Server is listening on %s:%d', listen, port);
    winston.info('Swagger-ui is available on %s:%d/docs', listen, port);
  });
});

更新:问题似乎是通过将app.listen更改为app.listen来解决的(process.env.PORT || 3000,function()

0 个答案:

没有答案