Am I making this more complicated than it is? Been working at this for hours and getting nowhere. This passes 2 out of the 4 tests. Need help passing 2 and 3
const urlStore = {};
app.post('/api/shorturl', (req, res) => {
const original = req.body.url;
if (!validUrl.isUri(original)) {
return res.json({ error: 'invalid url' });
} else {
const short = shortid.generate();
urlStore[short] = original;
res.json({ original_url : original, short_url : short});
}
});
app.get('/api/shorturl/<short_url>', (req, res) => {
const short = req.params.short_url;
if (urlStore.hasOwnProperty(short)) {
const original = urlStore[short];
res.redirect(original);
} else {
res.json({error: 'short url not found'});
}
});
how does “short url” looks like in request body? it seems like you are trying to reference it using a “url” rather than that “generated id” used in previous snippet, right?!