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 100kb

jsonLimit String

limit of the json body, default is 100kb

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:

confusedConfigurations :Object

configurations are confused to users {

}

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 true.

reloadOnDebug Boolean

whether reload on debug, default is true.

Source:
See:

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.

request.timeout Number

httpclient request default timeout, default is 5000 ms.

httpAgent.keepAlive Boolean

Enable http agent keepalive or not, default is true

httpAgent.freeSocketKeepAliveTimeout 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.freeSocketKeepAliveTimeout 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 中

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 encloding, 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:

middleware :Array

core enable middlewares

Source:

multipart

multipart parser options

Properties:
Name Type Description
autoFields Boolean

Auto set fields to parts, default is false. 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 []

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:

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

domainWhiteList Array

domain white list

protocolWhiteList Array

protocal white list

Source:

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: