首页 > 学院 > 开发设计 > 正文

翻译---express 4.x版本官网的app.set()的属性和使用方法

2019-11-08 02:39:53
字体:大 中 小
来源:转载
供稿:网友

app.set(name, value)

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().

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.

如果 名字 是 一个 应用程序 设置, 它 会影响 应用程序 的 行为方式。 下表 列出 应用程序 设置

PropertyTypeValueDefault

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

More about the HTTP ETag header.

 

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地址是不可靠的。

zhǐ指 shì示 yìng应 yòng用 chéng程 xù序 shì是 yī一 gè个 qián前 zhì置 dài代 lǐ理 de的 bèi背 hòu后 , bìng并 yòng用 x - f o r w a r d e d * tóu头 lái来 què确 dìng定 lián连 jiē接 hé和 kè客 hù户 duān端 de的 I P dì地 zhǐ址 。 zhù注 : x - f o r w a r d e d * tóu头 hěn很 róng容 yì易 wěi伪 zào造 hé和 jiǎn检 cè测 dào到 de的 I P dì地 zhǐ址 shì是 bù不 kě可 kào靠 de的 。

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地址的客户端连接到阵列。要启用它,请使用“信任代理选项表”中描述的值。

mò默 rèn认 qíng情 kuàng况 xià下 xìn信 rèn任 dài代 lǐ理 yǐ已 jìn禁 yòng用 。 qǐ启 yòng用 shí时 , biǎo表 shì示 shì试 tú图 tōng通 guò过 qián前 miàn面 dī的 dài代 lǐ理 huò或 yī一 xì系 liè列 dài代 lǐ理 lián连 jiē接 lái来 què确 dìng定 kè客 hù户 duān端 de的 I P dì地 zhǐ址 。 de的 r e q . i p s cái财 chǎn产 , rán然 hòu后 , bāo包 hán含 I P dì地 zhǐ址 de的 kè客 hù户 duān端 lián连 jiē接 dào到 zhèn阵 liè列 。 yào要 qǐ启 yòng用 tā它 , qǐng请 shǐ使 yòng用 “ xìn信 rèn任 dài代 lǐ理 xuǎn选 xiàng项 biǎo表 ” zhōng中 miáo描 shù述 de的 zhí值 。

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
TypeValue
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/128linklocal - 169.254.0.0/16, fe80::/10uniquelocal - 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 nth 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
TypeValue
Boolean

true enables weak ETag. This is the default setting.false disables ETag altogether.

StringIf "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版本)
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表