Skip to content

Commit

Permalink
feat: app.httpClient alias to app.httpclient (#5304)
Browse files Browse the repository at this point in the history
let `@Inject() httpClient` work

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Introduced a new alias for `httpClient` to improve accessibility and
usage within the application.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
fengmk2 authored Apr 12, 2024
1 parent 23866ad commit a6ebe0f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 8 additions & 0 deletions lib/egg.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
7 changes: 4 additions & 3 deletions test/lib/core/httpclient.test.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit a6ebe0f

Please sign in to comment.