Heroku node.js API超时

Heroku node.js API超时,node.js,mongodb,heroku,mean-stack,Node.js,Mongodb,Heroku,Mean Stack,我有一个应用程序在heroku上运行了一年多,没有任何问题。这是一个简单的MEAN应用程序,它从API中提取一些数据并将其显示在网站上 自2天起(数月内代码无变化)。我得到一个503超时错误代码 我曾尝试与Postman一起测试API,但我也遇到了同样的问题。在本地运行应用程序效果非常好。我试着直接从一个控制台查询数据库,这个控制台也能正常工作。任何人都知道问题可能是什么。我的端点路由的代码: app.get("/api/protocols", function(req, res){ P

我有一个应用程序在heroku上运行了一年多,没有任何问题。这是一个简单的MEAN应用程序,它从API中提取一些数据并将其显示在网站上

自2天起(数月内代码无变化)。我得到一个503超时错误代码

我曾尝试与Postman一起测试API,但我也遇到了同样的问题。在本地运行应用程序效果非常好。我试着直接从一个控制台查询数据库,这个控制台也能正常工作。任何人都知道问题可能是什么。我的端点路由的代码:

app.get("/api/protocols", function(req, res){
    Protocol.find(function(err, protocols){
        if(err){
           res.send(err);
        }
        res.json(protocols);
    });
});

app.get("/api/diagnostics", function(req, res){
    Diagnostic.find(function(err, protocols){
        if(err){
           res.send(err);
        }
        res.json(protocols);
    });
});

app.get('/api/references', function(req, res){
    Reference.find(function(err, references){
        if(err) {
            res.send(err);
        }
        res.json(references);
    });
});
以及非常简单的api的代码: angular.module('ProtocolService',[]).factory('ProtocolService',function($http){

}))

Heroku日志的一部分,显示3个api端点上的h12故障:

2018-04-17T11:24:57.082451+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/api/references" host=emctreatment.herokuapp.com request_id=44410e1e-7249-47d4-a927-90c840f229f7 fwd="213.127.92.1" dyno=web.1 connect=1ms service=30001ms status=503 bytes=0 protocol=https
2018-04-17T11:24:57.081331+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/api/protocols" host=emctreatment.herokuapp.com request_id=658d91ca-8f7e-4ad1-b8c3-6618b25abfe8 fwd="213.127.92.1" dyno=web.1 connect=1ms service=30001ms status=503 bytes=0 protocol=https
2018-04-17T11:25:11.244476+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/api/diagnostics" host=emctreatment.herokuapp.com request_id=b560d69d-c689-42c8-b18e-565f2addf6da fwd="213.127.92.1" dyno=web.1 connect=1ms service=30000ms status=503 bytes=0 protocol=https
2018-04-17T11:25:27.214363+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/api/protocols" host=emctreatment.herokuapp.com request_id=ba945119-a1df-4d0b-8b91-5d2c9062a79f fwd="213.127.92.1" dyno=web.1 connect=1ms service=30000ms status=503 bytes=0 protocol=https
2018-04-17T11:25:27.209571+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/api/references" host=emctreatment.herokuapp.com request_id=db3459b6-f3a6-4c19-a943-c9f43394e92e fwd="213.127.92.1" dyno=web.1 connect=1ms service=30001ms status=503 bytes=0 protocol=https
协议方案:

// grab the mongoose module
var mongoose = require('mongoose');

// define the Protocol model
// module.exports allows us to pass this to other files when it is called
module.exports = mongoose.model('Protocol', {
    PROTOCOL : String,
    CLASS    : String,
    Localisation: String,
    T       : String,
    N       : String,
    Treatment : String,
    considerations : String

});
诊断方案

    // grab the mongoose module
    var mongoose = require('mongoose');

    // define the Protocol model
    // module.exports allows us to pass this to other files when it is called
    module.exports = mongoose.model('Diagnostic', {
        Localisation    : String,
        T               : String,
        N               : String,
        ClinExams       : String,
        RadioPrim       : String,
        RadioNeck       : String,
        RadioDist       : String,
        Extra           : String,
        Paramedics      : String,
        Considerations  : String

    });
参考方案:

    // grab the mongoose module
var mongoose = require('mongoose');

// define the Reference model
// module.exports allows us to pass this to other files when it is called
module.exports = mongoose.model('Reference', {
    CLASS    : String,
    TEXT     : String,
    TDEF     : String,
    NDEF     : String

});
Server.js文件:

// modules =================================================
var express        = require('express');
var app            = express();
var mongoose       = require('mongoose');
var bodyParser     = require('body-parser');
var methodOverride = require('method-override');

// configuration ===========================================

// config files
var db = require('./config/db');

var port = process.env.PORT || 8080; // set our port
var url = process.env.DATABASEURL || db.url;
mongoose.connect(url); // connect to our mongoDB database (commented out after you enter in your own credentials)

// get all data/stuff of the body (POST) parameters
app.use(bodyParser.json()); // parse application/json 
app.use(bodyParser.json({ type: 'application/vnd.api+json' })); // parse application/vnd.api+json as json
app.use(bodyParser.urlencoded({ extended: true })); // parse application/x-www-form-urlencoded

app.use(methodOverride('X-HTTP-Method-Override')); // override with the X-HTTP-Method-Override header in the request. simulate DELETE/PUT
app.use(express.static(__dirname + '/public')); // set the static files location /public/img will be /img for users

// routes ==================================================
require('./app/routes')(app); // pass our application into our routes

// start app ===============================================
app.listen(port);   
console.log('Application running on port ' + port);             // shoutout to the user
exports = module.exports = app;                         // expose app

你能提供heroku的日志吗?最好知道哪个端点挂起,以及当它挂起并返回503时它在代码中的位置。没有人可以运行您的代码,因为它依赖于您未提供的一堆代码(如协议、参考和诊断模块)。@ElliotBlackburn编辑以显示日志
// modules =================================================
var express        = require('express');
var app            = express();
var mongoose       = require('mongoose');
var bodyParser     = require('body-parser');
var methodOverride = require('method-override');

// configuration ===========================================

// config files
var db = require('./config/db');

var port = process.env.PORT || 8080; // set our port
var url = process.env.DATABASEURL || db.url;
mongoose.connect(url); // connect to our mongoDB database (commented out after you enter in your own credentials)

// get all data/stuff of the body (POST) parameters
app.use(bodyParser.json()); // parse application/json 
app.use(bodyParser.json({ type: 'application/vnd.api+json' })); // parse application/vnd.api+json as json
app.use(bodyParser.urlencoded({ extended: true })); // parse application/x-www-form-urlencoded

app.use(methodOverride('X-HTTP-Method-Override')); // override with the X-HTTP-Method-Override header in the request. simulate DELETE/PUT
app.use(express.static(__dirname + '/public')); // set the static files location /public/img will be /img for users

// routes ==================================================
require('./app/routes')(app); // pass our application into our routes

// start app ===============================================
app.listen(port);   
console.log('Application running on port ' + port);             // shoutout to the user
exports = module.exports = app;                         // expose app