Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

95
Vistas
Rest API, take request fields. handle

I stood in a stupor. And I need help.
I do rest full api on express

I want to do this if a request comes in type: reset_password -> I sent an email to reset my password.(it can be both registration and auth)

But I don't know how to pass it into a query. And that is, how to do it. I trimmed the code.


const send = async (req, res) => {
    const key = req.query.apiKey;
    const type = req.query.type;
    const to = req.query.to;
        if (err) {
            console.log(err);
        } else if (rows.length == 0) {
            res.status(401).json({"apiKey":"error"})
              } else {
                  if (email.validate(to)) {
                        sendmail(type, to)
                      } else {
                        res.status(422)
                }
            }   
}

sendmail:

const nodemailer = require("nodemailer");
const ejs = require('ejs')
const path = require('path')

const sendmail = async (type, to, url) => {
  try {
    const reset_password = path.join(__dirname, "../template/resetpassword.ejs")
    const signup_auth = path.join(__dirname, "../template/signupauth.ejs")
    const sign_in_auth = path.join(__dirname, "../template/signinauth.ejs")
    const data = await ejs.renderFile(reset_password,signup_auth,sign_in_auth, { to, url } )

    let testAccount = await nodemailer.createTestAccount();

    // create reusable transporter object using the default SMTP transport
    let transporter = nodemailer.createTransport({
      host: "smtp.ethereal.email",
      port: 587,
      secure: false, // true for 465, false for other ports
      auth: {
        user: testAccount.user, // generated ethereal user
        pass: testAccount.pass, // generated ethereal password
      },
    });
   
   const send = await transporter.sendMail({
      from: 'dev@test.io',
      to: to,
      text: "Hello world?",
      subject: "test",
      html: ??? 
  })

  console.log("Success send: %s", nodemailer.getTestMessageUrl(send));

  }catch (err) {
    console.log('Error send: ' + err.message);
  }
}
module.exports = sendmail;

Now I have a question. How do I send a request: reset_password,signup_auth,sign_in_auth
That is, how do I pass it on to the type: reset_password,signup_auth,sign_in_auth

http://localhost:3000/api?apiKey=key&type=reset_password,signup_auth,sign_in_auth

How do I take it and process it?
I need to accept type=auth signup reset to api rest I'm sorry, maybe I didn't make my point correctly.
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda