node.js - Creating preprocessor function before Input -
i have game server input works on demand. else wrote it, hadn't finished before leaving company, , have built now. guy forgot basic things (checking multiloging, decoding variables etc). has lot of functions, , take week rebuild them.
app.post('/productionfarm', function(req, res) { (...) app.post('/skipproductionfarm') { (...) //and 200 more do know solution, how preprocessor function (one function inputs), on post input code first, continue or not doing app.post queries?.
if understand question correctly, want run function prior post routes. pretty simple using middleware:
app.post('/*', function(req, res, next) { if(checkinputs(req)) { // check successful next(); } else { // either handle error directly res.send(400, 'bad request'); // or use separate error handling middleware next(new error('bad request')); } }); note must come before of app.post calls.
Comments
Post a Comment