Me quedé en un estupor. Y necesito ayuda.
Descanso la api completa en express
Quiero hacer esto si llega una solicitud del type: reset_password -> Envié un correo electrónico para restablecer mi contraseña (puede ser registro y autenticación)
Pero no sé cómo pasarlo a una consulta. Y eso es, cómo hacerlo. Recorté el código.
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) } } }enviar correo:
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; Ahora tengo una pregunta. ¿Cómo envío una solicitud?: reset_password,signup_auth,sign_in_auth
Es decir, ¿cómo lo paso al tipo: reset_password,signup_auth,sign_in_auth
http://localhost:3000/api?apiKey=key&type=reset_password,signup_auth,sign_in_auth