auto-server-proxy
v1.0.6
Published
Auto Server Proxy
Downloads
2
Readme
For simply the router function
- check missing params
- get params
- use default value
- catch exceptions
- print logs
- add a router '/api/list' : show all routers
- support GET/POST/PUT (Note: the raw server object should support 'req.body', you can use 'restify' package)
Example
const AutoServerProxy=require("auto-server-proxy").AutoServerProxy;
function onAdd(req,res){
req.getParams(
["a","b"], //required params name (optional)
{a:1,b:3}, //default value (optional)
({a,b})=>{
//if return true then send {status:"OK"}
//if return false then send {status:"ERROR"}
//if throw exception then send {status:"ERROR",error:exception}
//else send the return value
// if you forget return a value then send {status:"ERROR",error:`No response from '' - check code`}
// you also can use 'res.send()' to send your custom data
return p1+p2;
}
);
}
let serverProxy=new AutoServerProxy(server/*http server object*/);
serverProxy.get("/add",onAdd);
Syntax
req.getParams([paramsName,][defaultValues,]<callback>)