【问题标题】:How are HTTP responses managed by Node JS express?Node JS express 如何管理 HTTP 响应?
【发布时间】:2014-05-14 04:08:40
【问题描述】:

拥有这个简单的快递应用示例:

var express = require('express')
var app = express()


app.use(express.static(__dirname+'/public'))


app.get('/', function(request,response) {

    response.send("This wont matter if we got an index.hml after all")
})

app.listen(2311, function() {

    console.log("app escuchando en Maricela DDMM")
})

/public,我收到了一个index.html

当我摆脱这样的 html 时,send() 方法中的字符串将在浏览器中发送、接收和呈现。

response.send() 字符串讨论 HTTP 响应实际上发生什么,因为 HTML 是在浏览器上发送和呈现的?

【问题讨论】:

    标签: javascript node.js http express url-routing


    【解决方案1】:

    Express 按照添加的顺序遍历中间件链。您已将express.static 添加为第一个中间件,因此它将首先运行。

    如果express.static 找不到文件,它会调用next(),允许下一个中间件运行。这是您使用app.get('/' //... 设置的处理程序,它按照您的指示发送数据。

    【讨论】:

      【解决方案2】:

      我想它基本上是根据send中的参数设置header信息,然后发送http响应

      【讨论】:

        猜你喜欢
        • 2016-06-22
        • 2012-11-15
        • 1970-01-01
        • 1970-01-01
        • 2022-11-21
        • 2015-07-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多