Config

Config

new Config()

The configuration of egg application, can be access by app.config

Since:
  • 1.0.0
Source:

Members

(static) workerStartTimeout :Number

emit startTimeout if worker don't ready after workerStartTimeout ms

Source:

baseDir :String

The current directory of the application

Since:
  • 1.0.0
Source:
See:
  • {appInfo#baseDir}

bodyParser

The option of bodyParser middleware

Properties:
Name Type Description
enable Boolean

enable bodyParser or not, default is true

ignore String | RegExp | function | Array

won't parse request body when url path hit ignore pattern, can not set ignore when match presented

match String | RegExp | function | Array

will parse request body only when url path hit match pattern

encoding String

body's encoding type,default is utf8

formLimit String

limit of the urlencoded body. If the body ends up being larger than this limit, a 413 error code is returned. Default is 1mb

jsonLimit String

limit of the json body, default is 1mb

textLimit String

limit of the text body, default is 1mb

strict Boolean

when set to true, JSON parser will only accept arrays and objects. Default is true

queryString.arrayLimit Number

urlencoded body array's max length, default is 100

queryString.depth Number

urlencoded body object's max depth, default is 5

queryString.parameterLimit Number

urlencoded body maximum parameters, default is 1000

Source:

cluster :Object

Properties:
Name Type Description
listen Object

listen options, see https://nodejs.org/api/http.html#http_server_listen_port_hostname_backlog_callback

Properties
Name Type Description
path String

set a unix sock path when server listen

port Number

set a port when server listen

hostname String

set a hostname binding server when server listen

Source:

confusedConfigurations :Object

configurations are confused to users { [unexpectedKey]: [expectedKey], }

Source:

cookies

default cookie options

Properties:
Name Type Description
sameSite String

SameSite property, defaults is ''

httpOnly Boolean

httpOnly property, defaults is true

Source:

development

Properties:
Name Type Description
watchDirs Array

dirs needed watch, when files under these change, application will reload, use relative path

ignoreDirs Array

dirs don't need watch, including subdirectories, use relative path

fastReady Boolean

don't wait all plugins ready, default is false.

reloadOnDebug Boolean

whether reload on debug, default is true.

overrideDefault Boolean

whether override default watchDirs, default is false.

overrideIgnore Boolean

whether override default ignoreDirs, default is false.

reloadPattern Array | String

whether to reload, use https://github.com/sindresorhus/multimatch

Source:

dump

dump config

It will ignore special keys when dumpConfig

Properties:
Name Type Description
ignore Set

keys to ignore

Source:

env :String

The environment of egg

Since:
  • 1.0.0
Source:
See:
  • {appInfo#env}

HOME :String

The current HOME directory

Since:
  • 1.0.0
Source:
See:
  • {appInfo#HOME}

hostHeaders :String

Detect request' host from specified headers, not case-sensitive. Only worked when config.proxy set to true.

Since:
  • 1.0.0
Source:

httpclient

The option for httpclient

Properties:
Name Type Description
enableDNSCache Boolean

Enable DNS lookup from local cache or not, default is false.

dnsCacheLookupInterval Boolean

minimum interval of DNS query on the same hostname (default 10s).

request.timeout Number

httpclient request default timeout, default is 5000 ms.

httpAgent.keepAlive Boolean

Enable http agent keepalive or not, default is true

httpAgent.freeSocketTimeout Number

http agent socket keepalive max free time, default is 4000 ms.

httpAgent.maxSockets Number

http agent max socket number of one host, default is Number.MAX_SAFE_INTEGER @ses https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER

httpAgent.maxFreeSockets Number

http agent max free socket number of one host, default is 256.

httpsAgent.keepAlive Boolean

Enable https agent keepalive or not, default is true

httpsAgent.freeSocketTimeout Number

httpss agent socket keepalive max free time, default is 4000 ms.

httpsAgent.maxSockets Number

https agent max socket number of one host, default is Number.MAX_SAFE_INTEGER @ses https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER

httpsAgent.maxFreeSockets Number

https agent max free socket number of one host, default is 256.

Source:

i18n

I18n options

Properties:
Name Type Description
defaultLocale String

默认语言是美式英语,毕竟支持多语言,基本都是以英语为母板

dirs Array

多语言资源文件存放路径,不建议修改

queryField String

设置当前语言的 query 参数字段名,默认通过 query.locale 获取 如果你想修改为 query.lang,那么请通过修改此配置实现

cookieField String

如果当前请求用户语言有变化,都会设置到 cookie 中保持着, 默认是存储在key 为 locale 的 cookie 中

cookieDomain String

存储 locale 的 cookie domain 配置,默认不设置,为当前域名才有效

cookieMaxAge String | Number

cookie 默认 1y 一年后过期, 如果设置为 Number,则单位为 ms

Source:

ipHeaders :String

Detect request' ip from specified headers, not case-sensitive. Only worked when config.proxy set to true.

Since:
  • 1.0.0
Source:

jsonp

jsonp options

Properties:
Name Type Description
callback String

jsonp callback method key, default to ['_callback', 'callback' ]

limit Number

callback method name's max length, default to 50

csrf Boolean

enable csrf check or not. default to false

whiteList String | RegExp | Array

referrer white list

Source:

keys :String

The key that signing cookies. It can contain multiple keys seperated by ,.

Since:
  • 1.0.0
Source:
See:

logger

logger options

Properties:
Name Type Description
dir String

directory of log files

encoding String

log file encoding, defaults to utf8

level String

default log level, could be: DEBUG, INFO, WARN, ERROR or NONE, defaults to INFO in production

consoleLevel String

log level of stdout, defaults to INFO in local serverEnv, defaults to WARN in unittest, defaults to NONE elsewise

disableConsoleAfterReady Boolean

disable logger console after app ready. defaults to false on local and unittest env, others is true.

outputJSON Boolean

log as JSON or not, defaults to false

buffer Boolean

if enabled, flush logs to disk at a certain frequency to improve performance, defaults to true

errorLogName String

file name of errorLogger

coreLogName String

file name of coreLogger

agentLogName String

file name of agent worker log

coreLogger Object

custom config of coreLogger

Source:

logrotator

logrotator options

Properties:
Name Type Description
filesRotateByHour Array

list of files that will be rotated by hour

filesRotateBySize Array

list of files that will be rotated by size

maxFileSize Number

Max file size to judge if any file need rotate

maxFiles Number

pieces rotate by size

maxDays Number

keep max days log files, default is 31. Set 0 to keep all logs.

rotateDuration Number

time interval to judge if any file need rotate

maxDays Number

keep max days log files

Source:

maxIpsCount :Integer

max ips read from proxy ip header, default to 0 (means infinity) to prevent users from forging client ip addresses via x-forwarded-for

Since:
  • 2.25.0
Source:
See:

maxProxyCount :Integer

please use maxIpsCount instead

Since:
  • 2.21.0
Deprecated:
  • Yes
Source:

meta

The option of meta middleware

Properties:
Name Type Description
enable Boolean

enable meta or not, default is true

logging Boolean

enable logging start request, default is false

Source:

middleware :Array

core enable middlewares

Source:

multipart

multipart parser options

Properties:
Name Type Description
mode String

which mode to handle multipart request, default is stream, the hard way. If set mode to file, it's the easy way to handle multipart request and save it to local files. If you don't know the Node.js Stream work, maybe you should use the file mode to get started.

fileModeMatch String | RegExp | function | Array

special url to use file mode when global mode is stream.

autoFields Boolean

Auto set fields to parts, default is false. Only work on stream mode. If set true,all fields will be auto handle and can acces by parts.fields

defaultCharset String

Default charset encoding, don't change it before you real know about it

fieldNameSize Integer

Max field name size (in bytes), default is 100

fieldSize String | Integer

Max field value size (in bytes), default is 100kb

fields Integer

Max number of non-file fields, default is 10

fileSize String | Integer

Max file size (in bytes), default is 10mb

files Integer

Max number of file fields, default is 10

whitelist Array | function

The white ext file names, default is null

fileExtensions Array

Add more ext file names to the whitelist, default is []

tmpdir String

The directory for temporary files. Only work on file mode.

Source:

name :String

The name of the application

Since:
  • 1.0.0
Source:
See:
  • {appInfo#name}

notfound

The option of notfound middleware

It will return page or json depend on negotiation when 404, If pageUrl is set, it will redirect to the page.

Properties:
Name Type Description
pageUrl String

the 404 page url

Source:

onClientError :function

This function / async function will be called when a client error occurred and return the response.

The arguments are err, socket and application which indicate current client error object, current socket object and the application object.

The response to be returned should include properties below:

Properties:
Name Type Attributes Description
body String | Buffer <optional>

the response body

status Number <optional>

the response status code

headers Object <optional>

the response header key-value pairs

Source:
Example
exports.onClientError = async (err, socket, app) => {
  return {
    body: 'error',
    status: 400,
    headers: {
      'powered-by': 'Egg.js',
    }
  };
}

pkg :Object

package.json

Since:
  • 1.0.0
Source:
See:
  • {appInfo#pkg}

protocolHeaders :String

Detect request's protocol from specified headers, not case-sensitive. Only worked when config.proxy set to true.

Since:
  • 1.0.0
Source:

proxy :Boolean

Whether application deployed after a reverse proxy, when true proxy header fields will be trusted

Since:
  • 1.0.0
Source:

rundir :String

The directory of server running. You can find application_config.json under it that is dumpped from app.config.

Since:
  • 1.0.0
Source:

security

security options

Properties:
Name Type Description
defaultMiddleware String

default open security middleware

csrf Object

whether defend csrf attack

xframe Object

whether enable X-Frame-Options response header, default SAMEORIGIN

hsts Object

whether enable Strict-Transport-Security response header, default is one year

methodnoallow Object

whether enable Http Method filter

noopen Object

whether enable IE automaticlly download open

nosniff Object

whether enable IE8 automaticlly dedect mime

xssProtection Object

whether enable IE8 XSS Filter, default is open

csp Object

content security policy config

referrerPolicy Object

referrer policy config

dta Object

auto avoid directory traversal attack

domainWhiteList Array

domain white list

protocolWhiteList Array

protocal white list

Source:

serverTimeout :Number

server timeout in milliseconds, default to 2 minutes.

for special request, just use ctx.req.setTimeout(ms)

Source:
See:

siteFile :Object

The option of siteFile middleware

You can map some files using this options, it will response immdiately when matching.

Source:
Example
// specific app's favicon, => '/favicon.ico': 'https://eggjs.org/favicon.ico',
config.siteFile = {
  '/favicon.ico': 'https://eggjs.org/favicon.ico',
};

static

Static file serve

Properties:
Name Type Description
prefix String

/public/ by default

dir String

static files store dir, ${baseDir}/app/public by default

maxAge Number

cache max age, default is 0

Source:
See:

view

view default config

Properties:
Name Type Attributes Default Description
root String <optional>
${baseDir}/app/view

give a path to find the file, you can specify multiple path with , delimiter

cache Boolean <optional>
true

whether cache the file's path

defaultExtension String <optional>

defaultExtension can be added automatically when there is no extension when call ctx.render

defaultViewEngine String <optional>

set the default view engine if you don't want specify the viewEngine every request.

mapping Object

map the file extension to view engine, such as { '.ejs': 'ejs' }

Source:

watcher

watcher options

Properties:
Name Type Description
type string

event source type

Source: