Я использую Angular Universal (Angular 8, серверная часть nodejs и экспресс-сервер).Все работает нормально, но я получаю ошибки тайм-аута запроса: https://devcenter.heroku.com/articles/error-codes#h12-request-timeout.
Oct 07 11:19:45 example heroku/router: at=error code=H12 desc="Request timeout" method=GET path="/some-url" host=example.com request_id=88c597ae-2c20-4f2b-ac49-fbb757fc2c93 fwd="xx.xx.xx.xx" dyno=web.1 connect=0ms service=30001ms status=503 bytes=0 protocol=https
Как я могу узнать, что вызывает эти тайм-ауты и как с ними справиться?
Мой экспресс-сервер выглядиткак:
import 'zone.js/dist/zone-node';
import 'reflect-metadata';
import {enableProdMode} from '@angular/core';
import {ngExpressEngine} from '@nguniversal/express-engine';
import {provideModuleMap} from '@nguniversal/module-map-ngfactory-loader';
import * as express from 'express';
import * as compression from 'compression';
import * as cookieparser from 'cookie-parser';
import {join} from 'path';
enableProdMode();
const app = express();
app.use(compression());
app.use(cookieparser());
const PORT = process.env.PORT || 4000;
const DIST_FOLDER = join(process.cwd(), 'dist');
const {AppServerModuleNgFactory, LAZY_MODULE_MAP} = require('./dist/server/main');
app.use((req, res, next) => {
if (req.headers['x-forwarded-proto'] !== 'https' && req.hostname !== 'localhost') {
if (req.url === '/robots.txt') {
next();
return;
}
res.redirect(301, 'https://' + req.hostname + req.url);
}
if (req.hostname.startsWith('www.')) {
const host = req.hostname.slice(4, req.hostname.length);
res.redirect(301, 'https://' + host + req.url);
}
next();
}
);
app.engine('html', ngExpressEngine({
bootstrap: AppServerModuleNgFactory,
providers: [
provideModuleMap(LAZY_MODULE_MAP)
]
}));
app.set('view engine', 'html');
app.set('views', join(DIST_FOLDER, 'browser'));
app.get('*.*', express.static(join(DIST_FOLDER, 'browser'), {
maxAge: '1y'
}));
app.get('*', (req, res) => {
res.headers = res.getHeaders();
res.render('index', {
req: req,
res: res,
providers: [
{
provide: 'REQUEST', useValue: (req)
},
{
provide: 'RESPONSE', useValue: (res)
}
]
}, (err: Error, html: string) => {
res.status(html ? 200 : 500).send(html || err.message);
});
});
app.listen(PORT, () => {
console.log(`Node Express server listening on http://localhost:${PORT}`);
});