From b7b0a5bf9d68b056cd79db4241fc667598c876fa Mon Sep 17 00:00:00 2001 From: liunian Date: Fri, 5 Jun 2020 22:02:49 +0800 Subject: [PATCH] customize request timeout with env --- README.md | 4 ++++ lib/util/requestData.ts | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0e61a1e..3dd71c6 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,10 @@ openapi-generator from swagger 2.0 or OpenAPI 3.0: `openapi-generator url http://xxx/v2/api-docs -c true` +Default request timeout is 5000ms, customize timeout with `requestTimeout` env. + +`requestTimeout=10000 openapi-generator url http://xxx/v2/api-docs -c true` + ## Use Config `openapi-generator config ./xxx.js` or `openapi-generator config ./xxx.json` diff --git a/lib/util/requestData.ts b/lib/util/requestData.ts index a510523..729638e 100644 --- a/lib/util/requestData.ts +++ b/lib/util/requestData.ts @@ -1,8 +1,10 @@ import * as request from 'request'; +const timeout = process.env.requestTimeout ? (parseInt(process.env.requestTimeout, 10) || 5000) : 5000; + export async function requestData(url: string) { return new Promise((resolve, reject) => { - request(url, { timeout: 5000 }, (error, response, body) => { + request(url, { timeout: timeout }, (error, response, body) => { if (error) { console.warn('[GenSDK] err', error); reject(error);