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/128linklocal - 169.254.0.0/16, fe80::/10uniquelocal - 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, fc00::/7Set 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 }) |
新聞熱點
疑難解答