Skip to content

Instantly share code, notes, and snippets.

@supersheep
Last active December 12, 2015 09:39
Show Gist options
  • Save supersheep/4753352 to your computer and use it in GitHub Desktop.
Save supersheep/4753352 to your computer and use it in GitHub Desktop.
function (req, res, next) {
var url,reqdata;
if(!req.xhr){next();}
url = urlmod.parse(req.url).pathname;
reqdata = {
get : req.query,
post : req.body,
header: req.headers
};
reqdata.header.cookie = req.cookies;
TestCaseModel.findByUrl(url, function (err, rows) {
if(err){res.send(500,err);return;}
if(!rows || !rows.length){next();return;}
rows.forEach(function (row) {
var schema;
try{
schema = eval("(" + row.reqschema + ")");
}catch(e){
res.send(500,e+row.reqschema);
}
if(Schema(schema)(reqdata)){
res.send(row.resdata);
}
});
next();
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment