• express--app.set


    app.set(name,value)

    name可以自己定义,也可以定义为应用设置(application settings) ,下面介绍几个应用设置

    PropertyTypeValueDefault

    case sensitive routing

    Boolean 支持区分大小写 废弃. Treats "/Foo" and "/foo" as the same.

    env

    String 设置环境模式

    process.env.NODE_ENV(NODE_ENVenvironment 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` 设置选项
    TypeValue
    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/16fe80::/10
    • uniquelocal - 10.0.0.0/8172.16.0.0/12192.168.0.0/16fc00::/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

    信任从前台代理服务器作为客户机的第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 设置选项
    TypeValue
    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
      })
  • 相关阅读:
    CSS选择器
    HTML2
    html
    http协议
    python--Selectors模块/队列
    Linux系统管理02----目录和文件管理
    Linux系统管理01-----系统命令
    02作业 linux第一章和第三章命令
    01作业 Linux系统管理应用
    01:计算机硬件组层与基本配置------02计算机系统硬件核心知识
  • 原文地址:https://www.cnblogs.com/ouzilin/p/7906089.html
Copyright © 2020-2023  润新知