Link Expander Template
- Next.js
- TypeScript
See where any short link really goes before you tap it: every redirect, the real destination and its domain.
A Next.js app that expands short links. Paste a bit.ly, t.co, youtu.be or any other link and see the page it really lands on, how many redirects it took and the destination’s domain, with buttons to open or copy the real link. Use it to check links before you click them, or lift the API route to unwrap links in your own app or moderation queue.

What it does
- The real destination
- Follows the link to where it ends up and shows the full URL, with the domain picked out so lookalikes stand out.
- Every redirect
- Counts the redirects it followed, and on paid plans draws each hop in between as a chain.
- Recent links
- Keeps your last eight lookups on the device, so you can reopen one without spending a call.
- Shareable results
- Add ?url= to the page address to expand a link on load, handy for bookmarks and support replies.
- Keeps your key private
- The browser only talks to your own API route, which checks the link, caches answers and limits each visitor to 10 lookups a minute.
How it works
The API route: it checks the link, answers from the cache when it can, and calls URL Unshortener.
/** GET /api/expand?url=...: follows a short link to where it really goes. */
export async function GET(request: Request) {
let url = str(new URL(request.url).searchParams.get('url'), 2000);
if (!url) return fail('Paste a link to expand');
if (!/^https?:\/\//i.test(url)) url = `https://${url}`;
try {
new URL(url);
} catch {
return fail('That doesn’t look like a link');
}
const key = `expand:${url}`;
const hit = fromCache<Expanded>(key, TTL_MS);
if (hit) return Response.json(hit);
const blocked = guard(request);
if (blocked) return blocked;
return respond(async () => {
const data = await callApi<Expanded>('urlunshortener', { json: { url } });
toCache(key, data);
return data;
});
}Deploy it
- Get a free API key
The free plan includes 200 credits a month, no card needed. Create your key.
- Deploy it
Click Deploy to Vercel. Vercel copies the repo to your GitHub account and asks for
APIVERVE_API_KEY: paste your key there. - Open your app
Vercel builds it and gives you a live URL, usually in about a minute. Every push to the repo redeploys it.
Try the URL Unshortener API — the call this template makes
No key required to try it. Get a key to use it in your app.
{
"status": "ok",
"error": null,
"data": {
"source": "https://bit.ly/3k3j4",
"destination": "http://www.allclimbing.com/archive/2009/09/climbing-video-alex-puccio-on-trice-v12/",
"unshortened": true,
"redirectCount": 1,
"destinationDomain": "www.allclimbing.com",
"redirectChain": [
"https://bit.ly/3k3j4",
"http://www.allclimbing.com/archive/2009/09/climbing-video-alex-puccio-on-trice-v12/"
]
}
}