Tell us what’s happening:
I have a question about URL Shortener Microservice’s third case. When I res.redirect to the URL (https://www.google.com ) it always return refused to connect. I search it up online and they said try example.com, if that works , it’s a restriction on Google’s side.
So right now example.com is working , but all other URLs are not. I want to know which is the problem, the res.redirect code, gitpod or the restriction just updated recently?
This is the third case:
3. When you visit /api/shorturl/<short_url>
, you will be redirected to the original URL.
Your code so far
app.get(‘/api/shorturl/:num’, (req,res) => {
const shortValue = parseInt(req.params.num);
let originalUrl = null;
for(const url in urlDataBase){
if(urlDataBase[url] === shortValue){
originalUrl = url;
break;
}
}
if(originalUrl){
console.log(originalUrl);
res.redirect(originalUrl);
}
else{
res.json({err: “Failed”});
}
});
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Challenge Information:
Back End Development and APIs Projects - URL Shortener Microservice