0
안녕하세요. 나는 POST 요청을 처리해야 마녀에서 파일을 보내고 경로 매개 변수로 지정된 경로에서 압축을 풀어야한다 ... 나는 그것이 작동하지 않는 이유를 모르겠다. 어쩌면 나는 어리 석다. 컬 명령을 사용하여 PNodeJs http : //www.google.com/support/bin/answer.py?hl=ko&hl=ko 안녕하세요. 숙제를해야하고 왜 작동하지 않는지 잘 모르겠습니다.
function handle_post(req,res,path,cb){
function warn(err,event){
if(err)
console.warn(`Request ${event}, could not close ${path}`)
else
console.warn(`Request ${event}, ${path} closed succesfully`)
}
if(Fs.existsSync(path))
return cb(400,JSON.stringify({error: "file already exist"}));
var out= Fs.createWriteStream(path);
res.pipe(Zlib.createGunzip()).pipe(out);
out.on('finish',() => cb(200,JSON.stringify({error : null, "written bytes":out.bytesWritten})+'\n'));
req.on('aborted',() => warn(err,'aborted'));
req.on('error',(err)=>{
cb(500,JSON.stringify({error : err.message, "written bytes":ws.bytesWritten})+'\n')
});
}
var s=Http.createServer(
(req,res) => {
console.log("Request: "+req.method+" URL: "+req.url);
function send(code,json_string){
res.writeHead(code,{"Content-Type" : "application/json"});
res.end(json_string)
}
if(req.method=='GET')
handle_get(home+req.url,send);
else if(req.method=='POST'){
var parsed_url=Url.parse(req.url,true);
var path=parsed_url.query.path;
if(!path)
return send(400,JSON.stringify({error : 'Missing path'})+'\n');
handle_post(req,res,home+'/'+path,send);
}
});
s.listen(8080);