Redirect not Passing test

Ive rewritten this redirect 5 times now, and it still just doesnt want to pass the test. Any help is greatly appreciated.

  app.get('/api/shorturl/:suffix', (req, res)=> {
  let userUrl = req.params.suffix;
  ShortUrl.find({suffix: userUrl}).then(function(foundUrls) {
    let urlRedirect = foundUrls[0];
    res.redirect(urlRedirect.original_url);
  });
});

Hi there,

Your mongo uri is wrong. You haven’t changed the default <user>:<password> to a username and password that you get from your atlas mongo instance. Keep in mind that you need to remove the < and > too when you change them.
This is a good article by FCC on how to setup an mongodb atlas and get the uri from it.

In addition, when you managed to connect to mongodb, I highly recommend to remove you mongo uri from your code and add it to your .env file or in the secrets tab in replit.
Edit: Just to make this point clear. If your mongo uri was correct, I could’ve seen it and connected to your database. This is a security concern that you must avoid.

Also, when running on replit, I guess and I’m not 100% sure about this, it is safer to use node and not nodemon as nodemon relies on file system watches which won’t work as expected on replit. For you to change this go to the .replit file and change the line run = "npm run dev" to run= "npm run start". These two scripts point to what you have here in package.json file:

  "scripts": {
    "start": "node server.js",
    "dev": "nodemon server.js"
  },

Hope that helps!

I removed it, sorry I shouldve mentioned that. I have it saved properly in a notepad, just didnt want that info on a public forum. Repl.it doesnt do secrets anymore, and they have you use their process, but i found pasting the uri easier in this instance. Also, thanks for the heads up on nodemon, i wasnt aware of that!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.