tst.js 1015 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. const expressValidator = require('./');
  2. const { check, checkSchema, oneOf, validationResult } = require('./check');
  3. const { matchedData } = require('./filter');
  4. const express = require('express');
  5. const bodyParser = require('body-parser');
  6. const app = express();
  7. app.use(bodyParser.json());
  8. app.use(bodyParser.text());
  9. app.all('/*', [
  10. check('id').escape()
  11. ], (req, res) => {
  12. const data = matchedData(req, { onlyValidData: false });
  13. const result = validationResult(req);
  14. res.json({
  15. data,
  16. errors: result.array()
  17. });
  18. });
  19. // app.use(expressValidator());
  20. // app.use((req, res) => {
  21. // req.checkBody('id').custom(value => {
  22. // return new Promise(resolve => {
  23. // setTimeout(() => {
  24. // resolve();
  25. // }, 3000);
  26. // });
  27. // });
  28. // req.checkBody({
  29. // id: {
  30. // notEmpty: { errorMessage: 'not empty' }
  31. // }
  32. // });
  33. // req.getValidationResult().then(result => {
  34. // res.json({
  35. // errors: result.mapped()
  36. // });
  37. // });
  38. // });
  39. app.listen(3001);