Skip to content

Commit 2927bb7

Browse files
committed
change module's name
1 parent b38dc72 commit 2927bb7

File tree

3 files changed

+49
-8
lines changed

3 files changed

+49
-8
lines changed

README.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
$ npm i express-suite
1818
```
1919

20-
### routeCheck
20+
## routeCheck
2121

2222
This middleware will handle all requests to non-registered routes for you.
2323

@@ -26,6 +26,7 @@ In the config option, you can specify a route to handle all requests to non-exis
2626
If no config option is passed, the middleware will send a **404** to those requests.
2727

2828
```javascript
29+
//Dependencies
2930
const express = require('express');
3031

3132
//Require the routeCheck Middleware
@@ -53,6 +54,46 @@ app.use(routeCheck(app, option));
5354
app.listen(5003);
5455
```
5556

57+
## emptyInputCheck
58+
59+
This middleware validates all inputs to all routes (unless used at router level) by checking the **body** of both POST and GET requests.
60+
61+
```javascript
62+
//Dependencies
63+
const express = require('express');
64+
const bodyParser = require('body-parser');
65+
66+
//Require the routeCheck Middleware
67+
const { emptyInputCheck } = require('../app');
68+
69+
//Initialize the App
70+
const app = express();
71+
72+
// bodyParser Middleware
73+
app.use(
74+
bodyParser.json({
75+
limit: '5mb',
76+
extended: true,
77+
}),
78+
);
79+
80+
//The emptyInputCheck Middleware
81+
app.use(
82+
emptyInputCheck({
83+
checkGet: true,
84+
}),
85+
);
86+
87+
//Load Routes
88+
const example = require('./routes/example');
89+
90+
//Use Routes
91+
app.use('/', example);
92+
93+
//Start the server
94+
app.listen(5003);
95+
```
96+
5697
## Tests
5798

5899
The poject uses **Jest** for testing.

app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ const routeCheck = (app, opt) => {
8080
/**
8181
* @returns {function():void}
8282
*/
83-
const inputValidation = ({
83+
const emptyInputCheck = ({
8484
checkGet = true,
8585
}) => {
8686

@@ -153,5 +153,5 @@ const inputValidation = ({
153153

154154
module.exports = {
155155
routeCheck,
156-
inputValidation,
156+
emptyInputCheck,
157157
};

test/server.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
//Dependencies
22
const express = require('express');
33
const bodyParser = require('body-parser');
4-
const { routeCheck, inputValidation, } = require('../app');
4+
const { routeCheck, emptyInputCheck, } = require('../app');
55
//Global Constant
66
const PORT = 5003;
77

88
//Initialize the App
99
const app = express();
1010

11-
// bodyParser Middleware
11+
//bodyParser Middleware
1212
app.use(bodyParser.json({
1313
limit: '5mb',
1414
extended: true,
@@ -20,8 +20,8 @@ app.all('*', (req, res, next) => {
2020
next();
2121
});
2222

23-
//The inputValidation middleware
24-
app.use(inputValidation({ checkGet: true, }));
23+
//The emptyInputCheck middleware
24+
app.use(emptyInputCheck({ checkGet: true, }));
2525

2626
//Exists
2727
app.get('/', (req, res) => {
@@ -47,7 +47,7 @@ app.post('/', (req, res) => {
4747
});
4848
});
4949

50-
50+
//The routeCheck middleware
5151
app.use(routeCheck(app, { path: '/PnF', }));
5252

5353

0 commit comments

Comments
 (0)