app.set(name,value)
name可以自己定義,也可以定義為應用設置(application settings) ,下面介紹幾個應用設置
Property | Type | Value | Default |
---|---|---|---|
|
Boolean | 支持區分大小寫 | 廢棄. Treats "/Foo" and "/foo" as the same. |
|
String | 設置環境模式 |
|
|
Varied | 設置ETag響應頭 |
|
|
String | 指定默認的JSONP回調名稱 |
|
|
String | JSON 替換的回調函數 |
|
|
Number | 在設置時,發送帶有指定數量空格的修飾的JSON字符串。 | 廢棄. |
|
String |
用於使用的查詢解析器,要么是“simple”,要么是“extended”。simple解析器基於節點的本地查詢解析器查詢字符串。extended 解析器基於qs |
"extended" |
|
Boolean | strict 路由模式 | Disabled. Treats "/foo" and "/foo/" as the same by the router. |
|
Number | The number of dot-separated parts of the host to remove to access subdomain. | 2 |
|
Varied |
表明該應用程序位於一個前端代理的后面,並使用 默認情況下,信任代理是禁用的。當啟用時,Express嘗試通過前端代理或一系列代理來確定客戶端的IP地址。要求的事情。然后,ips屬性包含了客戶端通過的IP地址的數組。要啟用它,請使用信任代理選項表中描述的值。 信任代理設置是使用proxy-addr包實現的。要了解更多信息,請參閱其文檔 |
Disabled. |
|
String or Array | 應用程序視圖的目錄或目錄數組。如果一個數組,視圖會按照數組中出現的順序查找 eg:app.set('views', path.join(__dirname, 'views')) |
|
|
Boolean | 支持視圖模板編譯緩存。 |
|
|
String | 當省略時使用的默認引擎擴展名 eg: app.set('view engine', 'ejs') //設置模板引擎為 ejs | |
|
Boolean | Enables the "X-Powered-By: Express" HTTP header. |
|
`trust proxy` 設置選項
Type | Value |
---|---|
Boolean | 如果正確,客戶端的IP地址被理解為 如果錯誤,程序是理解為直接面對互聯網和來自req.connection.remoteAddress客戶機的IP地址。這是默認設置。 |
IP addresses | 一個IP地址,子網,或一個IP地址的數組,和子網來信任。下面是預配置的子網名稱列表
Set IP addresses in any of the following ways: 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 | 信任從前台代理服務器作為客戶機的第n個跳轉 |
Function | Custom trust implementation. Use this only if you know what you are doing.
|
etag 設置選項
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. |