Express.js - 应用程序禁用()方法


应用程序禁用()方法禁用在此函数中传入的设置名称。此方法将设置名称设置为 False。我们还可以使用应用程序.设置()方法通过将其值传递为 False 来执行相同的功能。

语法

app.disable(name)

示例 1

使用名称"appDisable.js"创建一个文件,并复制以下代码片段。创建文件后,使用命令"节点应用程序禁用.js"来运行此代码。

// app.disable() Method Demo Example

// Importing the express module
const express = require('express');

// Initializing the express and port number
var app = express();

// Initializing the router from express
var router = express.Router();
var PORT = 3000;

// Disabling the property foo
app.disable('foo');

// Checking the foo property
console.log(app.get('foo'));

输出

C:\home
ode>> node appDisable.js false

示例 2

我们再来看一个示例。

// app.disable() Method Demo Example

// Importing the express module
const express = require('express');

// Initializing the express and port number
var app = express();

// Initializing the router from express
var router = express.Router();
var PORT = 3000;

// Disabling the property foo
app.disable('trust proxy');

// Checking the foo property
console.log("Trust proxy settings are set to: ", app.get('trust
proxy'));

输出

C:\home
ode>> node appDisable.js Trust proxy settings are set to: false

更新于: 2021 年 9 月 30 日

631 次浏览

开启你的职业生涯

通过完成课程获得认证

开始
广告
© . All rights reserved.