1.0.6 • Published 5 years ago

auto-server-proxy v1.0.6

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

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>)
1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago