Assigns setting name
to value
, where name
is one of the PRoperties from theapp settings table.
分配 设定 名字 给 值,这里的名字是一个 app 设定表 的属性
Calling app.set('foo', true)
for a Boolean property is the same as callingapp.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()
.
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 |
---|---|---|---|
| Boolean | Enable case sensitivity. 启用区分大小写 | Disabled. Treats "/Foo" and "/foo" as the same. 不启用。把"/Foo" and "/foo" 看作是一样的 |
| String | Environment mode. 列出所有环境变量及其赋值 |
|
| Varied | Set the ETag response header. For possible values, see the 设置 ETag 请求的 报头。对于 可能的 值,看 More about the HTTP ETag header. | |
| String | Specifies the default JSONP callback name. 指定 默认 jsonp 回调 名字(开启透明的 jsonp支持) |
|
| String | JSON replacer callback. JSON 替代者 回调 |
|
| Number | When set, sends prettified JSON string indented with the specified amount of spaces. 当 设置好 的时候, 发送 修饰好了的 和 打算的 指定大小的空间 json 字符串 | Disabled. 不启用 |
| 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" |
| Boolean | Enable strict routing. 启用 严格 的路由 选择(启用后不会忽略路径末尾的 '/') | Disabled. Treats "/foo" and "/foo/" as the 不启用。把"/Foo" and "/foo" 看作是一样的 same by the router. |
| Number | The number of dot-separated parts of the host to remove to access subdomain. 许多用点号 分隔的 主机部分被移除 为了访问 子域 | 2 |
| Varied | Indicates the app is behind a front-facing proxy, and to use the
The 指示应用程序是一个前置代理的背后,并用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. |
| 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. 如果是一个数组,这个视图 是 按出现在数组里的顺序 查询 的 |
|
| Boolean | Enables view template compilation caching. 启用 视图 模板 编译 缓存 |
在生产中true |
| String | The default engine extension to use when omitted. 当省略了的时候 默认的拓展引擎会被使用 | |
| Boolean | Enables the "X-Powered-By: Express" HTTP header. 启用"X-Powered-By,Express" HTTP 报头 |
|
Type | Value |
---|---|
Boolean | If If |
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 arrayWhen 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 |
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; }) |
Type | Value |
---|---|
Boolean |
|
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 }) |
新闻热点
疑难解答