简体   繁体   中英

nodemailer is never read and method='POST' never sent, routing problem

I'm trying to build a Website for myself and studyings. I've reached a wall in NodeJS where I can't fix it, already googling and stucked on it for two days.

when I set my var to nodemailer and require it, always display the message that the value it is declared but never read.

This also happens with the paths, the request is never read. Other problem is that I'm sending a POST to try send the e-mail but when I click to submit, it never send to console log to even test it.

I'd really appreciate some help on this.

 <div class="row block-9 justify-content-center mb-5">
          <div class="col-md-8 mb-md-5">             
            <h2 class="text-center">Estamos aqui para ajudar<br>por favor não exite em nos perguntar</h2>
            {{msg}}  
            <form class="bg-light p-5 contact-form" method="POST" action="send">
              <div class="form-group">
                <input type="text" class="form-control" placeholder="Nome" name="nome">
              </div>
              <div class="form-group">
                <input type="text" class="form-control" placeholder="Email">
              </div>
              <div class="form-group">
                <input type="text" class="form-control" placeholder="Assunto">
              </div>
              <div class="form-group">
                <textarea name="" id="" cols="30" rows="7" class="form-control" placeholder="Mensagem"></textarea>
              </div>
              <div class="form-group">
                <button type="submit" value="Enviar" class="btn btn-primary py-3 px-5"></button>
              </div>
            </form>          
          </div>
        </div>


The app.js:
const nodemailer = require('nodemailer');
const bodyParser = require('body-parser');
const hbs = require('express-handlebars');

var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');

var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');

var app = express();

app.set('view engine', 'hbs');
app.engine( 'hbs', hbs( {
    extname: 'hbs',
    layoutsDir: __dirname + '/views',
  }));


app.use(bodyParser.urlencoded({ extended: false}));
app.use(bodyParser.json());

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));


app.use('/', indexRouter);
app.use('/users', usersRouter);


module.exports = app;

The router on Index.js:

var express = require('express');
var router = express.Router();


/* GET home page. */

router.get('/', function(req, res, next) {
    res.render('index', {layout: 'index'});
  });


router.get('/contato', function(req, res) {
    res.render('contato', {layout: 'contato'});
  });

router.post('/contato', (req, res) => {
    console.log(req.body)    
})

module.exports = router;

'nodemailer' is declared but its value is never read.

Cannot POST /send

I fixed it:) Some times just go out and clear the mind makes you see the silly mistakes.

I was trying to send a post /contato instead of /send

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM