node/javascript 中的“位置”属性

" Location " property in node/javascript

我有这个代码:

let stats;
if (stats.isDirectory()) {
    response.writeHead(302, {Location: "server.html"});
}

我不知道 "Location" 是 javascript 属性 还是它只属于 Nodejs,我看不懂它的用法

Node 中的 writeHead 函数只需要一个 javascript object,所以在这个意义上 "Location" 是 js object 中的任意键。 writeHead documentation

就可以进入 object 的值以及它们的作用而言,这是一个普遍的 HTTP header 问题。 Here is some general info about headers and here 特别是关于位置的信息。

关于位置,Mozila 开发者网络说:

位置响应 header 指示要将页面重定向到的 URL。它仅在与 3xx(重定向)或 201(已创建)状态响应一起提供时提供意义。 所以在这种情况下:

if (stats.isDirectory()) {
    response.writeHead(302, {Location: "server.html"});
}

当我们在地址栏中输入类似http://127.0.0.1:5000/的内容时,它会自动重定向到server.html,所以这里"Location "定义了重定向地址。