fix: align api keepalive with gateway pool
This commit is contained in:
@@ -7,6 +7,8 @@ BRANCH="${BRANCH:-main}"
|
||||
PUBLIC_HTTP_PORT="${PUBLIC_HTTP_PORT:-12026}"
|
||||
API_PORT="${API_PORT:-3000}"
|
||||
API_HOST="${API_HOST:-127.0.0.1}"
|
||||
API_HTTP_KEEP_ALIVE_TIMEOUT_MS="${API_HTTP_KEEP_ALIVE_TIMEOUT_MS:-120000}"
|
||||
API_HTTP_HEADERS_TIMEOUT_MS="${API_HTTP_HEADERS_TIMEOUT_MS:-125000}"
|
||||
API_METRICS_HOST="${API_METRICS_HOST:-127.0.0.1}"
|
||||
API_METRICS_PORT="${API_METRICS_PORT:-9464}"
|
||||
API_ENABLE_SEND_WORKER="${API_ENABLE_SEND_WORKER:-true}"
|
||||
@@ -200,6 +202,8 @@ write_env() {
|
||||
NODE_ENV=production
|
||||
API_PORT=${API_PORT}
|
||||
API_HOST=${API_HOST}
|
||||
API_HTTP_KEEP_ALIVE_TIMEOUT_MS=${API_HTTP_KEEP_ALIVE_TIMEOUT_MS}
|
||||
API_HTTP_HEADERS_TIMEOUT_MS=${API_HTTP_HEADERS_TIMEOUT_MS}
|
||||
API_METRICS_HOST=${API_METRICS_HOST}
|
||||
API_METRICS_PORT=${API_METRICS_PORT}
|
||||
API_ENABLE_SEND_WORKER=${API_ENABLE_SEND_WORKER}
|
||||
|
||||
@@ -19,6 +19,11 @@ set -a
|
||||
source "$ENV_FILE"
|
||||
set +a
|
||||
|
||||
if [[ ! "${API_HTTP_KEEP_ALIVE_TIMEOUT_MS:-}" =~ ^[1-9][0-9]*$ || ! "${API_HTTP_HEADERS_TIMEOUT_MS:-}" =~ ^[1-9][0-9]*$ || "${API_HTTP_HEADERS_TIMEOUT_MS}" -le "${API_HTTP_KEEP_ALIVE_TIMEOUT_MS}" ]]; then
|
||||
echo "API_HTTP_KEEP_ALIVE_TIMEOUT_MS must be positive and API_HTTP_HEADERS_TIMEOUT_MS must be greater in $ENV_FILE." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "${API_ENABLE_SEND_WORKER:-}" != "true" ]]; then
|
||||
echo "API_ENABLE_SEND_WORKER=true is required in $ENV_FILE; refusing to deploy with SMS sending disabled." >&2
|
||||
exit 1
|
||||
|
||||
@@ -4,6 +4,7 @@ import { resolve } from 'node:path';
|
||||
const deploy = readFileSync(resolve(import.meta.dirname, 'production-deploy.sh'), 'utf8');
|
||||
const bootstrap = readFileSync(resolve(import.meta.dirname, 'production-bootstrap.sh'), 'utf8');
|
||||
const apiMain = readFileSync(resolve(import.meta.dirname, '../../api/src/main.ts'), 'utf8');
|
||||
const apiTimeouts = readFileSync(resolve(import.meta.dirname, '../../api/src/http-server-timeouts.ts'), 'utf8');
|
||||
const workerMain = readFileSync(resolve(import.meta.dirname, '../../api/src/send-worker.ts'), 'utf8');
|
||||
const required = [
|
||||
'compression_config=/etc/nginx/conf.d/cmpp-compression.conf',
|
||||
@@ -26,6 +27,14 @@ for (const marker of ['API_HOST="${API_HOST:-127.0.0.1}"', 'API_HOST=${API_HOST}
|
||||
if (!apiMain.includes("process.env.API_HOST?.trim() || '127.0.0.1'") || !apiMain.includes('app.listen(port, host)')) {
|
||||
throw new Error('NestJS API must bind to API_HOST and default to loopback');
|
||||
}
|
||||
for (const marker of ['API_HTTP_KEEP_ALIVE_TIMEOUT_MS', 'API_HTTP_HEADERS_TIMEOUT_MS']) {
|
||||
if (!`${deploy}\n${bootstrap}\n${apiTimeouts}`.includes(marker)) {
|
||||
throw new Error(`production deployment is missing the API keep-alive contract: ${marker}`);
|
||||
}
|
||||
}
|
||||
if (!apiMain.includes('configureApiHttpServerTimeouts(apiServer, process.env)')) {
|
||||
throw new Error('NestJS API must apply the explicit keep-alive contract to its HTTP server');
|
||||
}
|
||||
|
||||
for (const marker of [
|
||||
'CMPP_INBOUND_FAST_PATH_ENABLED=true',
|
||||
|
||||
Reference in New Issue
Block a user