URL Shortener: My App is Sending Me a File Back

URL Shortener: My App is Sending Me a File Back
0.0 0

#1

Here’s my code: https://glitch.com/edit/#!/url-s .

You can test it using this URL: https://url-s.glitch.me/api/shorturl/new/https://www.google.com .

After that, you’ll see a prompt asking you to download a COM file, like this image .

Anyone knows why is this happening?

Edit: the problem seems to be related to Firefox, because it only shows there.


#2

I can’t get your test URL to run.


#3

I don’t know. What do you get when you try running it?


#4

Nothing, when I click on your link, the window opens up and the url https://url-s.glitch.me/api/shorturl/new/https://www.google.com but nothing happens. A blank window just sits there.


#5

Are you using Firefox?

I just edited it to show the word "response" so that you can check if it’s working.


#6

I’m on Chrome on Windows 10.

Now I am seeing the word “response” but nothing else.

I think that at the point in your logic where you add your new shortened URL to the database (after line 48 in server.js?) you need to put a res.send(outputStr); and that outputStr is the output you want to go to your screen. Then you want to do something similar in every branch of your logic. Or you you could just create that outputStr in each logic branch and have res.end(outputStr); called at the end of that function, just calling it once.

Does that make sense? I’m no expert, but that’s how I approached it.


#7

The behavior I talked about in the original post shows on Firefox, not Chrome (I edit the original post before to mention that).

Thank you for your input. I see what you’re talking about. But I don’t think that this is the problem that is causing the behavior I’m talking about.


#8

Yeah, when I run it in FF, I get the same thing. I’m not sure why. If it were my code, I’d start commenting out lines and changing things to see where it is happening. I might start with some console.log statements to see where this is happening.

Sorry, I don’t know enough about nodejs to solve this without setting up the server myself and tearing it apart piece by piece.