File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -56,7 +56,13 @@ app.listen(5003);
5656
5757## emptyInputCheck
5858
59- This middleware validates all inputs to all routes (unless used at router level) by checking the ** body** of both POST and GET requests.
59+ This middleware checks for all empty inputs to all routes (unless used at a router level) by checking the ** body** of both POST and GET requests.
60+
61+ Note: 0 does count as a valid input.
62+
63+ All empty inputs will be met with a ** 400** and the message: ` { msg: 'Some fields are missing!' } ` .
64+
65+ You can specify the middleware to skip the check for ** GET** requests in the config option.
6066
6167``` javascript
6268// Dependencies
@@ -69,7 +75,7 @@ const { emptyInputCheck } = require('../app');
6975// Initialize the App
7076const app = express ();
7177
72- // bodyParser Middleware
78+ // bodyParser Middleware
7379app .use (
7480 bodyParser .json ({
7581 limit: ' 5mb' ,
@@ -78,9 +84,11 @@ app.use(
7884);
7985
8086// The emptyInputCheck Middleware
87+ // It's important that we place the our middleware after the bodyParser middleware
88+ // Make sure you call the emptyInputCheck middleware before the routes are loaded
8189app .use (
8290 emptyInputCheck ({
83- checkGet: true ,
91+ checkGet: true , // Wether to check the GET requests or not
8492 }),
8593);
8694
You can’t perform that action at this time.
0 commit comments