我已经在heroku上运行了一年多的应用程序而没有任何问题。它是一个简单的MEAN应用程序,它从API中提取一些数据并将其显示在网站上。
自2天以来(几个月内代码没有变化)。我收到了503超时错误代码。
我尝试过使用Postman测试API,但我遇到了同样的问题。在本地运行应用程序非常正常。我尝试直接从一个可以正常运行的控制台查询数据库。任何人都知道问题可能是什么。我的ENDPOINT路线的代码:
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){
function getProtocols(){
return $http.get('/api/protocols');
}
return {getProtocols: getProtocols};
});
部分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