Constructor
new Agent(options)
Parameters:
Name | Type | Description |
---|---|---|
options
|
Object | see EggApplication |
- Source:
Extends
Members
coreLogger :Logger
core logger for framework and plugins, log file is $HOME/logs/{appname}/egg-web
- Since:
- 1.0.0
- Inherited From:
- Source:
createAnonymousContext :String
Create an anonymous context, the context isn't request level, so the request is mocked.
then you can use context level API like ctx.service
- Inherited From:
- Source:
env
app.env delegate app.config.env
- Inherited From:
- Deprecated:
- Yes
- Source:
httpclient :HttpClient
HttpClient instance
- Inherited From:
- Source:
- See:
logger :Logger
application logger, log file is $HOME/logs/{appname}/{appname}-web
- Since:
- 1.0.0
- Inherited From:
- Source:
loggers :Object
All loggers contain logger, coreLogger and customLogger
- Since:
- 1.0.0
- Inherited From:
- Source:
messenger :Messenger
messenger instance
- Since:
- 1.0.0
- Inherited From:
- Source:
proxy
app.proxy delegate app.config.proxy
- Inherited From:
- Deprecated:
- Yes
- Source:
Methods
addSingleton(name, create)
create a singleton instance
Parameters:
Name | Type | Description |
---|---|---|
name
|
String | unique name for singleton |
create
|
function | AsyncFunction | method will be invoked when singleton instance create |
- Inherited From:
- Source:
cluster(clientClass, optionsopt) → {ClientWrapper}
almost the same as Agent.cluster API, the only different is that this method create Follower.
Parameters:
Name | Type | Description |
---|---|---|
clientClass
|
function | client class function |
[
options
]
|
Object |
|
- Inherited From:
- Source:
- See:
createContext(req, res) → {Context}
Create egg context
Parameters:
Name | Type | Description |
---|---|---|
req
|
Req | node native Request object |
res
|
Res | node native Response object |
- Inherited From:
- Source:
curl(url, opts) → {Object}
http request helper base on httpclient, it will auto save httpclient log.
Keep the same api with httpclient.request(url, args)
.
See https://github.com/node-modules/urllib#api-doc for more details.
Parameters:
Name | Type | Description |
---|---|---|
url
|
String | request url address. |
opts
|
Object |
|
- Inherited From:
- Source:
Example
```js
const result = await app.curl('http://example.com/foo.json', {
method: 'GET',
dataType: 'json',
});
console.log(result.status, result.headers, result.data);
```
getLogger(name) → {Logger}
Get logger by name, it's equal to app.loggers['name'], but you can extend it with your own logical.
Parameters:
Name | Type | Description |
---|---|---|
name
|
String | logger name |
- Inherited From:
- Source:
inspect() → {Object}
print the information when console.log(app)
- Since:
- 1.0.0
- Inherited From:
- Source:
Example
```js
console.log(app);
=>
{
name: 'mockapp',
env: 'test',
subdomainOffset: 2,
config: '<egg config>',
controller: '<egg controller>',
service: '<egg service>',
middlewares: '<egg middlewares>',
urllib: '<egg urllib>',
loggers: '<egg loggers>'
}
```