0
Im in node.js. WriteHead()
newはtypeErrorを継続的に与えています。私はresponse.wrtieHead(200,{'Context-Type':'text/plain'})
として使用していますが、同じエラーを出しています。助けてください。 ここに私のコードです。TypeError:定義されていないノードの「writeHead」js
var http = require('http');
var fs = require('fs');
function send404Response(response){
response.writeHead(200,{"content-Type":"text/plain"});
response.write("404 paage");
response.end();
}
function onRequest(request,response){
if(response.method== 'GET' && response.url('/')){
response.writeHead(200, {"content-Type":"text/html"});
fs.createReadStream("./index.html").pipe(response);
}
else{
send404Response();
}
}
http.createServer(onRequest).listen(8888);
console.log("server is running");
ありがとうございました。今実行していますが、404を投げますが、index.htmlファイルに移動する必要があります。@Sparw –
"if"条件の直前にrequest.pathを表示できますか? – Sparw
はい。それは未定義と言います。 –