Initial commit
This commit is contained in:
commit
d7af9332c1
1674 changed files with 119641 additions and 0 deletions
35
node_modules/express-validator/docs/feature-whole-body-validation.md
generated
vendored
Normal file
35
node_modules/express-validator/docs/feature-whole-body-validation.md
generated
vendored
Normal file
|
@ -0,0 +1,35 @@
|
|||
---
|
||||
id: whole-body-validation
|
||||
title: Whole Body Validation
|
||||
---
|
||||
|
||||
Sometimes you need to validate requests whose body is a string, an array, or even a number!
|
||||
That's why you can omit the field to validate and check `req.body` directly:
|
||||
|
||||
```js
|
||||
const bodyParser = require('body-parser');
|
||||
const express = require('express');
|
||||
const { body } = require('express-validator');
|
||||
|
||||
const app = express();
|
||||
|
||||
// Will handle text/plain requests
|
||||
app.use(bodyParser.text());
|
||||
|
||||
app.post('/recover-password', body().isEmail(), (req, res) => {
|
||||
// Assume the validity of the request was already checked
|
||||
User.recoverPassword(req.body).then(() => {
|
||||
res.send('Password recovered!');
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
This setup should be able to handle the following request:
|
||||
|
||||
```http
|
||||
POST /recover-password HTTP/1.1
|
||||
Host: localhost:3000
|
||||
Content-Type: text/plain
|
||||
|
||||
my@email.com
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue