2
我在Node中編寫了一個非常複雜且工作的js腳本。我升級了我的服務器,發現它失敗了。在回到基礎,我發現,這個簡單的腳本失敗,控制檯消息,如下圖所示它,當我去http://www.mapworldlive.com:8899/test從我的瀏覽器:正在使用非常簡單的腳本使用節點發送它們後無法設置標頭
var http = require("http");
var express = require('express')
var app = express()
var server = http.createServer(app);
server.on('request', app);
server.listen(8899);
var chttime=new Date(),showdate=chttime.toDateString(),secs=chttime.getSeconds(),mins=chttime.getMinutes(),hrs=chttime.getHours(),day=chttime.getDay(),month=chttime.getMonth(),year=chttime.getFullYear();
console.log("Test Server started: "+hrs+":"+mins+" "+showdate);
app.use('/test',function(req, res) {
console.log("hello world")
res.end()
})
響應:
Test Server started: 14:23 Sat Feb 04 2017
hello world
Error: Can't set headers after they are sent.
請幫助我讓別人在我的情況下得到幫助!
堆棧跟蹤:
Error: Can't set headers after they are sent.
at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:356:11)
at expressInit (/var/www/vhosts/mapworldlive.com/dev.mapworldlive.com/node_modules/express/lib/
iddleware/init.js:23:42)
at Layer.handle [as handle_request] (/var/www/vhosts/mapworldlive.com/dev.mapworldlive.com/node
modules/express/lib/router/layer.js:95:5)
at trim_prefix (/var/www/vhosts/mapworldlive.com/dev.mapworldlive.com/node_modules/express/lib/
outer/index.js:312:13)
at /var/www/vhosts/mapworldlive.com/dev.mapworldlive.com/node_modules/express/lib/router/index.
s:280:7
at Function.process_params (/var/www/vhosts/mapworldlive.com/dev.mapworldlive.com/node_modules/
xpress/lib/router/index.js:330:12)
at next (/var/www/vhosts/mapworldlive.com/dev.mapworldlive.com/node_modules/express/lib/router/
ndex.js:271:10)
at query (/var/www/vhosts/mapworldlive.com/dev.mapworldlive.com/node_modules/express/lib/middle
are/query.js:44:5)
at Layer.handle [as handle_request] (/var/www/vhosts/mapworldlive.com/dev.mapworldlive.com/node
modules/express/lib/router/layer.js:95:5)
at trim_prefix (/var/www/vhosts/mapworldlive.com/dev.mapworldlive.com/node_modules/express/lib/
outer/index.js:312:13)
這是所有的代碼是什麼? – Lex
爲了清晰起見,我將所有內容都刪除了 –