I can not do post Node js Router Express

0

I am using Express and Router to create the links of my api, but for some reason when I try to post it throws me an error 404 , but if you find me any get . When I check the browser console I can see that it does the post with the parameters of my form, but it does not find the route

// rutas de ligas

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

const pool = require('../../db');


router.get('/add', (req, res) => {
  res.render('links/add');
});

router.get('/x', (req, res) => {
  res.send('x');
});

router.post('/add', (req, res) => {
  console.log(req.body);
  res.send('recibido');
});


module.exports = router;
<form action="/links/adds" method="POST">
  <div class="form-group">
    <label for="">Nombre Del Proyecto</label><br>
    <input style="width: 50%;" type="text" name="name" autofocus><br>

    <label for="">URL</label><br>
    <input style="width: 50%;" type="url" name="url" autofocus><br>

    <label for="">Descripción</label><br>
    <textarea style="width: 100%;" name="descrip" placeholder="Descripción de proyecto">
                                    </textarea>
    <br>
    <br>
    <div class="card-footer">
      <input type="submit" value="submit" class="btn btn-secondary   pull-right">
    </div>
  </div>
</form>
    
asked by E.Rawrdríguez.Ophanim 31.12.2018 в 06:23
source

1 answer

3

I see in your form that you are putting the post method that points to '/ links / add'. However, in your router configuration you only capture '/ add'. You can start by seeing if there is the problem there. Greetings.

Another thing: in the router it captures post towards '/ add' however in the form you send it to '/ links / adds'. Check the additional letter 's' that you put in the form.

    
answered by 31.12.2018 / 10:18
source