Express--app.set

Source: Internet
Author: User

App.set (Name,value)

Name can be defined by itself, or it can be defined as app settings (Application settings), here are a few app settings

Property
Type Value Default

case sensitive routing

Boolean Case-sensitive support Abandoned. Treats "/foo" and "/foo" as the same.

env

String Setting the Environment mode

process.env.NODE_ENV( NODE_ENV environment variable) or "development".

etag

Varied

Setting the ETag response header

jsonp callback name

String Specify the default JSONP callback name

?callback=

json replacer

String callback function for JSON substitution

null

json spaces

Number When set, a JSON string that is decorated with a specified number of spaces is sent. Abandoned.

query parser

String

The query parser to use is either "simple" or "extended". Simple parser query string based on the local query parser of the node. Extended parser based on QS

"Extended"

strict routing

Boolean Strict routing mode 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

Indicates that the application is behind a front-end agent and uses X-Forwarded-* headers to determine the connection and IP address of the client. Note: X-Forwarded-* the headers is easily spoofed and the detected IP address is unreliable.

By default, the trust agent is disabled. When enabled, express attempts to determine the client's IP address through a front-end agent or a series of proxies. Ask for things. The IPs property then contains an array of IP addresses passed by the client. To enable it, use the values that are described in the Trust Proxy options table.

The Trust proxy settings are implemented using the PROXY-ADDR package. To learn more, see its documentation

Disabled.

views

String or Array An array of directories or directories for the application view. If an array, the view finds eg:app.set in the order in which they appear in the array (' views ', Path.join (__dirname, ' views ')

process.cwd() + ‘/views‘

view cache

Boolean Supports the view template compilation cache.

trueIn production.

view engine

String When omitted, use the default engine extension Eg:app.set (' View engine ', ' ejs ')//Set the template engine to Ejs

x-powered-by

Boolean Enables the "X-powered-by:express" HTTP header.

true

 

' Trust proxy ' setting options

Type Value
Boolean

If correct, the IP address of the client is understood to be the X-Forwarded-* leftmost entry in headers.

If wrong, the program is understood to be directly facing the Internet and the IP address from the Req.connection.remoteAddress client. This is the default setting.

IP addresses

An array of IP addresses, subnets, or an IP address, and subnets to trust. The following is a list of preconfigured 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 Appset ( ' trust proxy ' [ ' loopback '   ' linklocal '   ' uniquelocal ' ]) Span class= "token comment" >//specify multiple subnets as an array        span>          

When specified, the IP addresses or the subnets is 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

To trust the nth jump from the foreground proxy server as the client

Function

Custom Trust implementation. Use the If you know what is doing.

App.Set(' Trust proxy 'function  (Ip{if  (IP ===  ' 127.0.0.1 ' | | IP ===  ' 123.123.123.123 ' Span class= "token punctuation") return true; //trusted IPs else return span class= "token keyword" >false})        /span>            

 

ETag Settings Options
Type Value
Boolean

trueEnables weak ETag. This is the default setting.
falseDisables ETag altogether.

String If "Strong", enables strong ETag.
If "Weak", enables weak ETag.
Function

Custom ETag function implementation. Use the If you know what is doing.

app.set(‘etag‘, function (body, encoding) { return generateHash(body, encoding); // consider the function is defined })

Express--app.set

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.