Commit 413104d9 by Иван Кубота

Add connection timeout.

parent a036f87a
......@@ -58,7 +58,9 @@ app.use(function(req, res, next) {
});
app.use(router);
app.use(App.static('public'))
app.use(function(req, res, next) {
req.end('Nope');
})
try{
app.listen( APP_PORT );
}catch(e){
......
......@@ -52,5 +52,13 @@ module.exports = {
items:Object.values(data.products).filter(p=>p.category_id+'' === args.id+'')
});
}
},
'/api/hang': {
method: 'GET',
summary: 'Fetch category data with child cards',
options: {},
fn: async function(args) {
return await new Promise(()=>{});
}
}
};
\ No newline at end of file
......@@ -94,18 +94,23 @@ ${opt.required?'<span class="api-option-required">Required</span>': '<span class
for(let key in apis){
let api = apis[key], args;
router[api.method.toLowerCase()](key, async function(req, res) {
let timeout = setTimeout(()=>res.end('Timeout'), 10000);
try{
args = parseArgs( req, res, api.options );
}catch(e){
return res.end('Errors:\n' +e.map(e=>'\t'+e).join('\n'))
}
console.log(api.method, key, JSON.stringify(args));
res.header("Content-Type", "application/json; charset=utf-8");
try{
let result = await api.fn(args, req, res);
res.end(typeof result === 'string' ? result : JSON.stringify(result, null,1), 'utf-8');
clearTimeout(timeout)
}catch(e){
debugger
res.end(e.message+'\n'+e.stack)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment