Lloyd
05/26/2023, 4:43 PMts
const exampleShortenedUrls: ShortenedUrl[] = [
{ id: '2tg9xy3', url: 'https://example.com' },
{ id: '3f2tqv', url: 'https://en.wikipedia.org/wiki/Example.com' },
{ id: '48difn', url: 'www.google.com' },
];
...
const { pathname } = new URL(request.url);
const id = new URL(request.url).pathname.startsWith('/')
? pathname.slice(1)
: pathname;
const matchedUrl = exampleShortenedUrls.find((entry) => entry.id === id);
if (!matchedUrl) {
console.warn('Unable to find shortened URL', id);
} else {
console.info('Found shortened URL and redirecting user', id);
Response.redirect(matchedUrl.url, 302); // this does nothing?
}
return next();
"logs": [
{
"message": [
"Found shortened URL and redirecting user",
"2tg9xy3"
],
"level": "info",
"timestamp": 1685119189434
}
],