Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

413
Views
this.validateBody no está validando las claves, incluso las claves están en el cuerpo de la solicitud nodejs koa
yield this.validateBody({ password: 'required', email_id: 'required' });

tratando de validar el cuerpo de la solicitud, pero cuando todo está en él, todavía dice que los campos son obligatorios. todo está en él.

nodo 12.20.0

validación de koa 0.1.9

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

// Usar validación de koa

 'use strict'; var koa = require('koa'); var app = koa(); var router = require('koa-router')(); require('koa-validate')(app); app.use(require('koa-body')({multipart:true , formidable:{keepExtensions:true}})); app.use(router.routes()).use(router.allowedMethods()); router.post('/signup', function * () { //optional() means this param may not in the params. this.checkBody('name').optional().len(2, 20,"are you kidding me?"); this.checkBody('email').isEmail("your enter a bad email."); this.checkBody('password').notEmpty().len(3, 20).md5(); //empty() mean this param can be a empty string. this.checkBody('nick').optional().empty().len(3, 20); //also we can get the sanitized value var age = this.checkBody('age').toInt().value; yield this.checkFile('icon').notEmpty().size(0,300*1024,'file too large').move("/static/icon/" , function*(file,context){ //resize image }); if (this.errors) { this.body = this.errors; return; } });
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!