Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
kus-admin
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Кубота
kus-admin
Commits
413104d9
Commit
413104d9
authored
Feb 15, 2020
by
Иван Кубота
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add connection timeout.
parent
a036f87a
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
1 deletion
+17
-1
api.js
api.js
+3
-1
crud.js
src/api/crud.js
+9
-0
apiMappers.js
src/apiMappers.js
+5
-0
No files found.
api.js
View file @
413104d9
...
...
@@ -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
){
...
...
src/api/crud.js
View file @
413104d9
...
...
@@ -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
src/apiMappers.js
View file @
413104d9
...
...
@@ -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)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment