我一直在我的特定路线上遇到一些请求超时,并且不确定为什么会出现这种情况,但是希望获得一些有关如何找到并提高调试技能的建议。
到目前为止,我了解到Heroku日志显示30秒超时,因为请求一直没有结束,可以这么说。如果请求未在30秒内完成,Heroku将自动返回503。
我已经安装了登录条目,示例日志是
5:56.273149+00:00 heroku router - - at=error code=H12 desc="Request timeout" method=POST path="/league_fixtures" dyno=web.1 connect=0ms service=30000ms status=503 bytes=0 protocol=https
这条路线看起来像
app.post('/league_fixtures', async (req, res) => {
try {
const leagueName = req.body.league_name;
const fixtures = await queries.leagueFixtures(leagueName);
const file = await readFile('./views/partials/fixtures.ejs');
const fixtureTemplate = ejs.compile(file, { client: true });
const html = fixtureTemplate({ fixtures });
res.send({ html });
} catch (err) {
res.status(500).send({ error: err });
}
});
我正在像这样使用node-postgres
const { Pool } = require('pg');
let config;
if (process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'staging') {
config = { connectionString: process.env.DATABASE_URL, ssl: true };
} else {
config = {
host: 'localhost',
user: 'myuser',
database: 'mydatabase',
};
}
const pool = new Pool(config);
pool.on('error', (err) => {
console.error('Unexpected error on idle client', err);
process.exit(-1);
});
async function leagueFixtures(leagueName) {
const client = await pool.connect();
try {
const response = await client.query("SELECT * FROM fixtures WHERE league_name = $1", [leagueName]);
} catch (e) {
console.error('Error Occurred', e);
} finally {
client.release();
}
return response.rows;
}
是否有任何迹象表明我做错了,或者有任何调试提示可以帮助我深入了解