Issue Tracker 404 Middleware Issue

Issue Tracker 404 Middleware Issue
0

#1

In the following code, I couldn’t get any of the routes to work unless I moved the 404 middleware from server.js to inside the MongoDB connect function in api.js. Is there a better way to handle this?

'use strict';

const MongoClient = require('mongodb');
const ObjectId = require('mongodb').ObjectID;

module.exports = app => {
  MongoClient.connect(process.env.DB, (err, db) => {
    console.log("connection established");
    if(err) {
      console.log(err);
    } else {
      app.route('/api/issues/:project')
        .get((req, res) => {
          console.log(req.params.project);
        })
        .post((req, res) => {
          console.log(req.params.project);
        })
        .put((req, res) => {
          console.log(req.params.project);
        })
        .delete((req, res) => {
          console.log(req.params.project);
        });
    }
  });
};

#2

The 404 route must be the last one to be checked. If you share your glitch project we might help you.