Hi!, I’m doing this url shortener challenge and, despite being working, this two tests aren’t passing:
-When you visit /api/shorturl/<short_url>
, you will be redirected to the original URL.
-If you pass an invalid URL that doesn’t follow the valid http://www.example.com
format, the JSON response will contain { error: 'invalid url' }
Here you can try the App: https://corty.herokuapp.com/
Here is the code: https://github.com/NachoKai/boilerplate-project-urlshortener/blob/main/server.js
Challenge: URL Shortener Microservice
Link to the challenge:
Learn to code. Build projects. Earn certifications.Since 2015, 40,000 graduates have gotten jobs at tech companies including Google, Apple, Amazon, and Microsoft.
Sky020
November 16, 2020, 1:35am
#2
Welcome, NachoKai.
It seems like the issue is the logic here:
newURL.save((err, url) => {
if (err) {
console.error(err);
} else if (requestedUrl.match(regex)) {
res.json({
short_url: url.short_url,
original_url: url.original_url,
uuid: url.uuid,
});
} else {
res.json({ error: "Invalid URL" });
}
});
If the URL is invalid, it should not be saved, and an error should be responded with.
Also, you have a much more complicated regex than the user story requires:
If you pass an invalid URL that doesn’t follow the valid http://www.example.com
format
Here is the test input: ftp:/john-doe.org
Here is your app output:
{"short_url":"https://corty.herokuapp.com/api/shorturl/pAWt13VrF","original_url":"ftp:/john-doe.org","uuid":"pAWt13VrF"}
I hope this helps
1 Like