Cuando pruebo mi backend en el localhost, funciona correctamente, pero cuando lo despliego en heroku me manda el siguien error:
Access to XMLHttpRequest at 'https://chango-tareas-backend.herokuapp.com/api/send-email' from origin 'https://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Esta es la linea de codigo encargarda de enviar correos a traves de nodemailer
//ruta para enviar el correo con nodemailer
router.post('/send-email', cors(), async (req, res) => {
const { nombre, email, mensaje, url, destino } = req.body;
contentHtml = `
<h1>CV solicitante ${nombre}<h1>
<ul>
<li>Contactar a: ${email}</li>
<li>${mensaje}</li>
</ul>
<a href="${url}">Click para ver</a>
`;
const transporter = nodemailer.createTransport({
host: 'host_outlock',
port: port,
secure: false,
auth: {
user: 'micorreo@hotmail.com',
pass: 'mipassword'
}
});
try{
const info = await transporter.sendMail({
from: "'ChangoTareas' <abisur_yue@hotmail.com>",
to: `${destino}`,
subject: `Solicitud de registro ${nombre}`,
text: 'Hola guapo :v',
html: contentHtml
});
}catch(err){
next(err);
}
console.log('Message sent', info.messageId);
res.status(200).send({ data: 'Success' });
});
En el console log de heroku me arroja las siguientes excepciones
2021-01-19T04:35:32.154277+00:00 app[web.1]: (node:36) UnhandledPromiseRejectionWarning: ReferenceError: next is not defined 2021-01-19T04:35:32.154291+00:00 app[web.1]: at /app/src/routes/index.js:128:9 2021-01-19T04:35:32.154292+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:97:5) 2021-01-19T04:35:32.154416+00:00 app[web.1]: (node:36) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag
--unhandled-rejections=strict
(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) 2021-01-19T04:35:32.154521+00:00 app[web.1]: (node:36) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. 2021-01-19T04:35:54.733967+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/api/send-email" host=chango-tareas-backend.herokuapp.com request_id=ba1f5e44-615f-4545-ab66-254db83c67a1 fwd="187.227.25.218" dyno=web.1 connect=1ms service=30000ms status=503 bytes=0 protocol=https