aboutsummaryrefslogtreecommitdiff
path: root/node_modules/express-validator/test/helpers/example.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/express-validator/test/helpers/example.js')
-rw-r--r--node_modules/express-validator/test/helpers/example.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/node_modules/express-validator/test/helpers/example.js b/node_modules/express-validator/test/helpers/example.js
new file mode 100644
index 0000000..b50f8bf
--- /dev/null
+++ b/node_modules/express-validator/test/helpers/example.js
@@ -0,0 +1,29 @@
+var util = require('util'),
+ express = require('express'),
+ expressValidator = require('../../index'),
+ app = express.createServer();
+
+app.use(express.bodyParser());
+app.use(expressValidator);
+
+app.post('/:urlparam', function(req, res) {
+
+ req.assert('postparam', 'Invalid postparam').notEmpty().isInt();
+ req.assert('getparam', 'Invalid getparam').isInt();
+ req.assert('urlparam', 'Invalid urlparam').isAlpha();
+
+ req.sanitize('postparam').toBoolean();
+
+ var errors = req.validationErrors();
+ if (errors) {
+ res.send('There have been validation errors: ' + util.inspect(errors), 500);
+ return;
+ }
+ res.json({
+ urlparam: req.param('urlparam'),
+ getparam: req.param('getparam'),
+ postparam: req.param('postparam')
+ });
+});
+
+app.listen(8888);