Express does not run route

Asked

Viewed 20 times

0

This is my index, but when calling the drones route, it displays the error:

CANNOT GET /drones/

But before it worked normally, it stopped working suddenly.

const express = require('express');
const bodyParser = require('body-parser');
const config = require('config');

//Importando rotas
const droneRouter = require('./routes/drones')

const app = express();

app.use(bodyParser.json());

app.use('/drones', droneRouter)

app.listen(config.get('api.port'), () => {
    createTable();
    console.log(`Servidor rodando na porta ${config.get('api.port')}`)
})

And this is the route file

const router = require('express').Router();
const TabelaDrone = require('./TabelaDrone');
const Drone = require('./Drone');

router.get('/drones/', async (request, response) => {
    const page = request.query._page;
    const limit = request.query._limit;
    console.log('aqui')
    if(page && limit){
        const results = await TabelaDrone.pagination(page, limit)
        response.status(200);
        response.send(JSON.stringify(results));
    }
    else{
        const results = await TabelaDrone.list();
        response.status(200);
        response.send(JSON.stringify(results));
    }
})

module.exports = router;
  • 2

    You do this app.use('/drones', droneRouter) and router.get('/drones/', the final route should be /drones/drones/

  • That’s right. Thank you, I didn’t mean to change the route and I didn’t even notice. Thanks, it helped too much, I was going to be hitting my head endlessly kkk

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.