gpt4 book ai didi

node.js - 回复未结束

转载 作者:太空宇宙 更新时间:2023-11-04 00:18:13 25 4
gpt4 key购买 nike

我正在为我们的一个项目创建一个前端应用程序,用于用户、集群、(单) Node 管理等。

我决定使用 HTML 和 JavaScript 创建前端,并使用 NodeJS 来实现服务器端功能。

我已经创建了网络服务器,可以处理定义的路由和文件;我决定将操作拆分为函数。根据我收集的有关 JavaScript 的信息,如果参数不是对象,则按值调用;如果参数是对象,则按引用调用?

如果是这种情况,为什么我不能 end() 来自外部函数的请求?如果可以的话,我该怎么做?

谢谢!

代码如下供引用。

// Define server functionality
if (request.method === "GET") {
// All GET functions/routes go here
if (routes[request.url]) {
// Route was found!
// Execute handler function
routes[request.url](request, response);
} else {
// No such route found in the hashtable
// Check if it's a file
var filePath = __dirname + request.url;
if (fs.existsSync(filePath)) {
// It's a file and was found!
//zOMG!!!1!elf
var mimeType = mime.contentType(path.extname(filePath));
var content = null;
if (mimeType.indexOf("text") > -1) {
// File contains text
content = fs.readFileSync(filePath, "UTF-8");
} else {
// File is binary
content = fs.readFileSync(filePath);
}
//console.log(mimeType); // Output MIME type of each requested file
response.statusCode = 200;
response.setHeader("Content-Type", mimeType === false ? "application/octet-stream" : mimeType);
response.end(content);
} else {
// File not found!
console.log(`File ${filePath} was NOT FOUND!`);
console.log("Cannot serve null!");
error404(request, response);
}
}
}

function error404(request, response) {
"use strict";

response.statusCode = 404;
response.end();
}

最佳答案

我自己找到了答案

sleep 过少的典型症状。修改代码后忘记重启服务器了。

捂脸

关于node.js - 回复未结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45813308/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com