我的节点服务器是否需要在功能结束之前手动结束响应? [英] Does my node server need to manually end the response before the function ends?

查看:61
本文介绍了我的节点服务器是否需要在功能结束之前手动结束响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个节点服务器,并且正在使用express处理对它的POST请求.我的问题是,我必须在处理函数结束之前调用response.end()还是会自动发生?

I have a node server and I'm using express to process POST requests to it. My question is, do I have to call response.end() before my processing function ends or will that happen automatically?

我问的原因是因为我的服务器在前几个请求中可以正常工作,然后开始抛出请求超时"错误,所以我试图找出问题所在.

Why I'm asking is because my server works as expected for the first few requests, then it starts throwing "request timeout" errors, so I'm trying to track down the issue.

我还应该注意,如果有任何区别,我总是使用response.send()在响应中发送一些内容.

I should also note that I always send something in the response using response.send() if that makes any difference.

推荐答案

响应的结尾会自动处理.如果使用的是本机HTTP模块,则应始终终止服务器响应.但是,由于您使用的是Express,因此响应端会自动为您处理.

The ending of the response is handled automatically. If you were using the native HTTP module, you should always end server responses. But since you're using Express, the response end is automatically handled for you.

this.end(head ? null : body);

您可以在此处找到Express的响应逻辑

You can find Express' response logic here.

这篇关于我的节点服务器是否需要在功能结束之前手动结束响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆