Новый для Node, Express и Pug. Я не могу завершить этот вызов ajax. Я знаю, что он находит это, но время истекает, и я в отчаянии. Что я делаю не так?
Все, что я пытаюсь сделать, это отправить электронное письмо через сайт.
Мне показалось, что я понял все, что связано с маршрутизацией, я могу нормально перемещаться между страницами, но этот вызов ajax убивает меня. Независимо от того, что я делаю, я получаю ошибку ENOENT с неверным путем 'C: \ contactme'. Первоначальная настройка и навигация Express и Pug была очень простой, но я не могу понять, что я делаю неправильно. Все это выглядит правильно для меня.
Вот слушатель
$('#cntct').on('click', '.cntctsndbutt', function(){
let con = $(this).parents('.modal');
let email = $(con).find('#eml').val();
let message = $(con).find('#msg').val();
let output = {html:"<p>You have a new contact request</p><h3>Contact Details</h3><ul> <li>Email: "+ email +"</li></ul><h3>Message</h3><p>"+message+"</p>"};
console.log(new Date().getTime());
console.log(output);
var dest = 'http://localhost:3000/indexii/contactme';
console.log(dest);
$.ajax({
url: dest,
type: 'POST',
dataType: 'json',
data: JSON.stringify(output),
async: true,
cache: false,
contentType: 'application/json',
processData: false,
timeout: 3000,
success: function (response) {
console.log('anything');
console.log(response);
},
error: function(xhr, status, error) {
console.log( xhr);
console.log(status);
console.log(error);
}
});
});
Вот маршрутизатор page.js
var express = require('express');
var router = express.Router();
var nodemailer = require('nodemailer');
router.post('/contactme', function(req,res){
console.log(req);
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 587,
secure: false,
auth: {
user: '***@gmail.com',
pass: '***app password***'
},
});
let missive = {
from: '***@gmail.com', // sender address
to: '***@gmail.com', // list of receivers
subject: 'Node Contact Request', // Subject line
text: 'Hello world?', // plain text body
html: req // html body
};
transporter.sendMail(missive, (error, info) => {
if (error) {
return console.log(error);
}
console.log('Message sent: %s', info.messageId);
console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
res.render('contact', {msg:'Email has been sent'});
});
});
router.get('/', function(req, res, next) {
res.render('indexii', { title: 'Home'});
});
console.log('index router');
module.exports = router