app.set(name, value)
Assigns setting name
to value
, where name
is one of the properties from the app settings table.
分配 设定 名字 给 值,这里的名字是一个 app 设定表 的属性
Calling app.set('foo', true)
for a Boolean property is the same as calling app.enable('foo')
. Similarly, calling app.set('foo', false)
for a Boolean property
把 app.set('foo', true) 作为 一个 布尔类型 属性 是 和 app.enable('foo')一样的。 相似地, 把app.set('foo', false)作为 一个布尔类型属性
is the same as calling app.disable('foo')
.
是和 app.disable('foo')一样的。
Retrieve the value of a setting with app.get()
.
检索 设置 的值 用 app.get()
.
app.set('title', 'My Site');
app.get('title'); // "My Site"
Application Settings
应用 设定
If name
is one of the application settings, it affects the behavior of the application. The following table lists application settings.
如果 名字 是 一个 应用程序 设置, 它 会影响 应用程序 的 行为方式。 下表 列出 应用程序 设置
Property Type Value Default case sensitive routing
区分大小写
路由选择
Boolean Enable case sensitivity.
启用区分大小写
Disabled. Treats "/Foo" and "/foo" as the same.
不启用。把"/Foo" and "/foo" 看作是一样的
env
外部命令
String Environment mode.
列出所有环境变量及其赋值
process.env.NODE_ENV
(NODE_ENV
environment variable) or “development”.
etag
被请求变量的实体值,实体标签
Varied Set the ETag response header. For possible values, see the etag
options table.
设置 ETag 请求的 报头。对于 可能的 值,看 etag
options table
jsonp callback name
jsonp 回调名字
String Specifies the default JSONP callback name.
指定 默认 jsonp 回调 名字(开启透明的 jsonp支持)
?callback=
json replacer
json 替代者
String JSON replacer callback.
JSON 替代者 回调
null
空
json spaces
json 空间
Number When set, sends prettified JSON string indented with the specified amount of spaces.
当 设置好 的时候, 发送 修饰好了的 和 打算的 指定大小的空间 json 字符串
Disabled.
不启用
query parser
查询解析器
String The query parser to use, either “simple” or “extended”. The simple query parser is based on Node’s
查询解析器使用,要么 简单 要么 拓展。 这个简单 的 查询解析器 是基于 node 的 本地查询解析器,
native query parser, querystring. The extended query parser is based on qs.
querystring. 这个 拓展的 查询解析器 是基于 qs.querystring.
"extended" strict routing
严格的路由选择
(严格路径)
Boolean Enable strict routing.
启用 严格 的路由 选择(启用后不会忽略路径末尾的 '/')
Disabled. Treats "/foo" and "/foo/" as the
不启用。把"/Foo" and "/foo" 看作是一样的
same by the router.
subdomain
offset
子域名偏移量
Number The number of dot-separated parts of the host to remove to access subdomain.
许多用点号 分隔的 主机部分被移除 为了访问 子域
2 trust proxy
信任代理
Varied Indicates the app is behind a front-facing proxy, and to use the X-Forwarded-*
headers to determine the connection and the IP address of the client. NOTE: X-Forwarded-*
headers are easily spoofed and the detected IP addresses are unreliable.
trust proxy
is disabled by default. When enabled, Express attempts to determine the IP address of the client connected through the front-facing proxy, or series of proxies. The req.ips
property, then, contains an array of IP addresses the client is connected through. To enable it, use the values described in the trust proxy
options table.
The trust proxy
setting is implemented using the proxy-addr package. For more information, see its documentation.
指示应用程序是一个前置代理的背后,并用x-forwarded *头来确定连接和客户端的IP地址。注:x-forwarded *头很容易伪造并且检测到的IP地址是不可靠的。
trust proxy is disabled by default. When enabled, Express attempts to determine the IP address of the client connected through the front-facing proxy, or series of proxies. The req.ips property, then, contains an array of IP addresses the client is connected through. To enable it, use the values described in the trust proxy options table.
默认情况下信任代理已禁用。启用时,表示试图通过前面的代理或一系列代理连接来确定客户端的IP地址的req.ips财产,然后,包含IP地址的客户端连接到阵列。要启用它,请使用“信任代理选项表”中描述的值。
The trust proxy setting is implemented using the proxy-addr package. For more information, see its documentation.
信托代理设置使用代理地址封装实现。有关更多信息,请参见其文档。
Disabled. views
视图
String or Array A directory or an array of directories for the application's views.
应用程序视图的一个目录或者一组目录(用于存放模板文件)
If an array, the views are looked up in the order they occur in the array.
如果是一个数组,这个视图 是 按出现在数组里的顺序 查询 的
process.cwd() + '/views'
view cache
视图缓存
Boolean Enables view template compilation caching.
启用 视图 模板 编译 缓存
true
in production.
在生产中true
view engine
视图模板引擎
String The default engine extension to use when omitted.
当省略了的时候 默认的拓展引擎会被使用
x-powered-by
x驱动
Boolean Enables the "X-Powered-By: Express" HTTP header.
启用"X-Powered-By,Express" HTTP 报头
true
Options for `trust proxy` setting
Type Value Boolean If true
, the client’s IP address is understood as the left-most entry in the X-Forwarded-*
header.
If false
, the app is understood as directly facing the Internet and the client’s IP address is derived from req.connection.remoteAddress
. This is the default setting.
IP addresses An IP address, subnet, or an array of IP addresses, and subnets to trust. The following is the list of pre-configured subnet names.
- loopback -
127.0.0.1/8
, ::1/128
- linklocal -
169.254.0.0/16
, fe80::/10
- uniquelocal -
10.0.0.0/8
, 172.16.0.0/12
, 192.168.0.0/16
, fc00::/7
Set IP addresses in any of the following ways:
app.set('trust proxy', 'loopback') // specify a single subnet
app.set('trust proxy', 'loopback, 123.123.123.123') // specify a subnet and an address
app.set('trust proxy', 'loopback, linklocal, uniquelocal') // specify multiple subnets as CSV
app.set('trust proxy', ['loopback', 'linklocal', 'uniquelocal']) // specify multiple subnets as an array
When specified, the IP addresses or the subnets are excluded from the address determination process, and the untrusted IP address nearest to the application server is determined as the client’s IP address.
Number Trust the n
th hop from the front-facing proxy server as the client.
Function Custom trust implementation. Use this only if you know what you are doing.
app.set('trust proxy', function (ip) {
if (ip === '127.0.0.1' || ip === '123.123.123.123') return true; // trusted IPs
else return false;
})
Options for `etag` setting
Type Value Boolean true
enables weak ETag. This is the default setting.
false
disables ETag altogether.
String If "strong", enables strong ETag.
If "weak", enables weak ETag. Function Custom ETag function implementation. Use this only if you know what you are doing.
app.set('etag', function (body, encoding) {
return generateHash(body, encoding); // consider the function is defined
})
http://www.expressjs.com.cn/4x/api.html#app.set (English版本)