0
어떻게하면이 GET 요청을 iSpeech로 개선하여 요청할 때 iSpeech가 시간이 좀 걸릴 때 서버가 시간 초과되지 않도록 할 수 있습니다.Node.js : 서버가 응답 및 시간 초과를 기다립니다.
app.get("/", function(req, res) {
var url;
if (req.param("url")) {
url = unescape(req.param("url"));
return request({
uri: url,
encoding: "binary"
}, function(error, response, body) {
var audio, format;
if (!error && response.statusCode === 200) {
format = response.headers["content-type"];
audio = new Buffer(body.toString(), "binary");
return request.post({
headers: {
"content-type": format
},
url: ispeech_server,
body: audio
}, function(error, response, body) {
var parse;
if (!error && response.statusCode === 200) {
parse = querystring.parse(body);
return res.send(parse, {
"Content-Type": "application/json"
}, 500);
} else {
return res.send("Error - iSpeech API returned an error", {
"Content-Type": "text/plain"
}, 500);
}
});
} else {
return res.send("Invalid URL - File Not Found", {
"Content-Type": "text/plain"
}, 404);
}
});
} else {
return res.send("Invalid URL - File Not Set", {
"Content-Type": "text/plain"
}, 404);
}
});