Configure proxy trust
Enable proxy-related application behavior before registering routes or middleware.
Express.js · Module
Enables a named Boolean setting on an Express application. It returns the application instance and is equivalent to setting that Boolean property to true.
Calling app.enable(name) changes the named Boolean application setting to true and returns the application object, so the call can be chained. The setting name must be one of the properties listed in Express's application settings table.
app.enable(name)| Name | Type | Description |
|---|---|---|
name | String | The Boolean application-setting name to enable; it must be a property from the application settings table. |
Application
app.set(name, true) provides equivalent behavior.trust proxy and reading the resulting value as true.const express = require('express');
const app = express();
app.enable('trust proxy');
console.log(app.get('trust proxy'));
Creates an Express application, enables the Boolean trust proxy setting, and reads it back as true.
Enable proxy-related application behavior before registering routes or middleware.
Turn on a documented Boolean Express application setting during startup.
Enable a setting while retaining the application object for fluent setup code.
app.enable() do, and what does it return?app.enable(name) sets the named Boolean application setting to true and returns the Express application. For example, enabling trust proxy makes app.get('trust proxy') return true.
Follow-up: How else can the same Boolean setting be enabled? app.set('foo', true) is equivalent when foo is a Boolean property.
app.enable() accept?The argument is the setting name, represented as a string. It must identify one of the Boolean properties in the application settings table.
Follow-up: What happens for a non-Boolean setting? Use the setting-specific API or app.set() rather than treating it as an enable/disable flag.
app.enable()?A typical use is app.enable('trust proxy'), which enables proxy-trust behavior for the application. The setting can then be inspected with app.get('trust proxy') or app.enabled('trust proxy').
Follow-up: How would you turn the setting off? Call app.disable('trust proxy'), then app.disabled('trust proxy') reports true.
app.set()app.get()app.enabled()app.disable()app.disabled()