node.js - 错误: Can't set headers after they are sent using web-terminal

标签 node.js

我试图使用网络终端..当我运行我的服务器代码时,出现以下错误

Web-terminal accessible at http://127.0.0.1:1337/terminal

http.js:691
throw new Error('Can\'t set headers after they are sent.');
      ^
Error: Can't set headers after they are sent.
at ServerResponse.OutgoingMessage.setHeader (http.js:691:11)
at ServerResponse.res.setHeader (/home/praful/terminalcloud/node_modules/connect/lib/patch.js:63:22)
at redirect (/home/praful/terminalcloud/node_modules/web-terminal/lib/terminal.js:25:9)
at SendStream.<anonymous> (/home/praful/terminalcloud/node_modules/web-terminal/lib/terminal.js:90:21)
at SendStream.EventEmitter.emit (events.js:92:17)
at SendStream.redirect (/home/praful/terminalcloud/node_modules/send/lib/send.js:271:55)
at /home/praful/terminalcloud/node_modules/send/lib/send.js:321:41
at Object.oncomplete (fs.js:107:15)

我的服务器端代码是:

 var http        = require("http"),
    terminal    = require("web-terminal");

var app = http.createServer(function (req, res) {
    res.writeHead(200, {"Content-Type": "text/plain"});
    res.end("Hello World\n");
});

app.listen(1337);
console.log("Server running at http://127.0.0.1:1337/");

terminal(app);
console.log("Web-terminal accessible at http://127.0.0.1:1337/terminal");

如何解决这个问题。

最佳答案

我找到了这个问题的解决方案...我使用“connect”模块来创建服务器..

var connect = require('connect');
var terminal = require('web-terminal');
terminal(connect.createServer(
    connect.static(__dirname)
).listen(8080));

还将“web”目录的内容从 Web 终端包复制到您的服务器目录中...
现在您可以从 http://'servername':8080/index.html 访问 Web 终端

关于node.js - 错误: Can't set headers after they are sent using web-terminal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21379566/

相关文章:

javascript - 如何从 index.js 获取 TS 文件?

angularjs - 使用 Javascript 多次调用 REST API 或一次调用大型响应正文

javascript - 如何对需要其他模块的 Node.js 模块进行单元测试以及如何模拟全局 require 函数?

arrays - 向 bluebird 提供一个数组,调用 API,然后将结果集成到单个 JSON 输出中

node.js - 注册 Twitter 错误。无法验证

node.js - 使用 sequelize/node js 进行层次结构查询

node.js - 错误 插件加载失败 : hexo-deployer-git when I deploy the blog

node.js - Express 如何路由相似的 url 链接?

node.js - 在 Heroku 上运行多个 Node.js 脚本

node.js - 在我的前端和后端之间创建一个 webhook