標籤:編譯 可靠 als main comment csv custom 出現 host
app.set(name,value)
name可以自己定義,也可以定義為應用設定(application settings) ,下面介紹幾個應用設定
Property |
Type |
Value |
Default |
case sensitive routing
|
Boolean |
支援區分大小寫 |
廢棄. Treats "/Foo" and "/foo" as the same. |
env
|
String |
設定環境模式 |
process.env.NODE_ENV (NODE_ENV environment variable) or “development”.
|
etag
|
Varied |
設定ETag回應標頭 |
|
jsonp callback name
|
String |
指定預設的JSONP回調名稱 |
?callback=
|
json replacer
|
String |
JSON 替換的回呼函數 |
null
|
json spaces
|
Number |
在設定時,發送帶有指定數量空格的修飾的JSON字串。 |
廢棄. |
query parser
|
String |
用於使用的查詢解析器,要麼是“simple”,要麼是“extended”。simple解析器基於節點的本地查詢解析器查詢字串。extended 解析器基於qs |
"extended" |
strict routing
|
Boolean |
strict 路由模式 |
Disabled. Treats "/foo" and "/foo/" as the 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 |
表明該應用程式位於一個前端代理的後面,並使用X-Forwarded-* headers來確定用戶端的串連和IP地址。注意:X-Forwarded-* headers很容易被欺騙,檢測到的IP地址不可靠。 預設情況下,信任代理是禁用的。當啟用時,Express嘗試通過前端代理或一系列代理來確定用戶端的IP地址。要求的事情。然後,ips屬性包含了用戶端通過的IP地址的數組。要啟用它,請使用信任代理選項表中描述的值。 信任代理設定是使用proxy-addr包實現的。要瞭解更多資訊,請參閱其文檔 |
Disabled. |
views
|
String or Array |
應用程式視圖的目錄或目錄數組。如果一個數組,視圖會按照數組中出現的順序尋找 eg:app.set(‘views‘, path.join(__dirname, ‘views‘)) |
process.cwd() + ‘/views‘
|
view cache
|
Boolean |
支援視圖模板編譯緩衝。 |
true in production.
|
view engine
|
String |
當省略時使用的預設引擎副檔名 eg: app.set(‘view engine‘, ‘ejs‘) //設定模板引擎為 ejs |
|
x-powered-by
|
Boolean |
Enables the "X-Powered-By: Express" HTTP header. |
true
|
`trust proxy` 設定選項
Type |
Value |
Boolean |
如果正確,用戶端的IP地址被理解為X-Forwarded-* headers中最左邊的條目。 如果錯誤,程式是理解為直接面對互連網和來自req.connection.remoteAddress客戶機的IP地址。這是預設設定。 |
IP addresses |
一個IP地址,子網,或一個IP地址的數組,和子網來信任。下面是預配置的子網名稱列表
- 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 |
信任從前台Proxy 伺服器作為客戶機的第n個跳轉 |
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; })
|
etag 設定選項
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 })
|
express--app.set