Url shortening api landing page

Please log in to post a comment
Log in with GitHubCommunity feedback
- @ippotheboxer
Hi, there seems to be a bug in your url shortening code.
When I give a link, it says "undefined" on where the shortened link is supposed to show. The copy button also doesn't work. In the console, it says "Failed to load resource: the server responded with a status of 429 ()". Error 429 means too many requests. The Bitly API that you are using, with the free plan, only allows 5 requests to be made per month.
It would be better to use the cleanURI, the api provided, since it doesn't require an API key or have any limits. However if you tried to do this on the frontend and found this didn't work, this is due to CORS policy: if you create a very simple backend that hits up this API and then have the frontend fetch it, you could get around this error. You could even just ask chatGPT to create it with node and express if you aren't very familiar with how to do this.
Also, I can still submit a link even if I didn't put a link in. This will inevitably lead to errors no matter what API you use, so I recommend using .trim() method around the input to validate it and check if anything was given, and then you could use regex to check if the link is in a valid format.
Hope this helps!
Marked as helpful
Join our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord