From a6ebe0f49a9e1a8506c26a0bb4e89a32528aa727 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Fri, 12 Apr 2024 14:23:53 +0800 Subject: [PATCH] feat: app.httpClient alias to app.httpclient (#5304) let `@Inject() httpClient` work ## Summary by CodeRabbit - **New Features** - Introduced a new alias for `httpClient` to improve accessibility and usage within the application. --- lib/egg.js | 8 ++++++++ test/lib/core/httpclient.test.js | 7 ++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/egg.js b/lib/egg.js index d1fccf3590..aabba225b4 100644 --- a/lib/egg.js +++ b/lib/egg.js @@ -304,6 +304,14 @@ class EggApplication extends EggCore { return this[HTTPCLIENT]; } + /** + * @alias httpclient + * @member {HttpClient} + */ + get httpClient() { + return this.httpclient; + } + /** * All loggers contain logger, coreLogger and customLogger * @member {Object} diff --git a/test/lib/core/httpclient.test.js b/test/lib/core/httpclient.test.js index 75c4be7fb7..2b5fbb73e5 100644 --- a/test/lib/core/httpclient.test.js +++ b/test/lib/core/httpclient.test.js @@ -1,6 +1,4 @@ -'use strict'; - -const assert = require('assert'); +const assert = require('node:assert'); const mm = require('egg-mock'); const urllib = require('urllib'); const Httpclient = require('../../../lib/core/httpclient'); @@ -268,6 +266,9 @@ describe('test/lib/core/httpclient.test.js', () => { it('should app request auto set tracer', async () => { const httpclient = app.httpclient; + // httpClient alias to httpclient + assert(app.httpClient); + assert.equal(app.httpClient, app.httpclient); let reqTracer; let resTracer;