Test a post route in glitch (or in general)

Tell us what’s happening:

Hi - I’m starting the URL shortener project.

But quickly getting following error -
Cannot GET /api/shorturl/

I tried to do ‘’/api/shorturl/?url=test.com’’ as the URL to go to … I’m obviously not formulating a POST correctly and can’t seem to find on google how I should be doing it.

So, how do i test a POST route please?


Your code so far

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36.

Challenge: undefined

Link to the challenge:

You may want to review the following challenges that covered how to do this.

Thanks. Yes, realised I was using the whole app incorrect and the POST was coming from index.html form. Got it now.

So, I tried to cover the duplicate case - ie do not create a new short URL if the URL already exists in the database.

But, app is timing out on a dB find. I now am not even sure if my dB is connected. I have following code, but don’t seem to get a message about if the connection is good. How do i reset / restart the app completely to see if the connection is good? Not sure when this code not in a route is executed.

var db = mongoose.connection;
db.on(‘error’, console.error.bind(console, ‘connection error:’));
db.on(‘connected’, function() {
console.log(“dB Seems Connected OK”);

Later on in my code, I have the following -

  • I get past ‘‘good URL’’ print out - but the app hangs in the findOne() call. Not sure what is wrong here.


else {
console.log(“Good URL!”);
const shortURL = shortID.generate();

  URLShortDoc.findOne({originalURL: req.body.url}, (err, URLPair) => {
    if (err) {
      // not found - must not be a dupe hopefully
      var newDoc = new URLShortDoc({originalURL: req.body.url, shortURL: shortURL});
      console.log(newDoc.originalURL, ": ", newDoc.shortURL);

db.once(‘open’, function() {
// we’re connected!
console.log(“dB Seems Connected OK”);

Is zero. So definitely not connected. Not sure how to debug.

So, found - both mongodb and mongoose packages in packages.json way old. Updated and now at least getting status 2 = connecting… But am not seeing connected as a status and most of app not working - assume due to db down - though don’t get any other useful error messages either.