--- /dev/null
+{
+ "version": 1,
+ "include": ["/*"],
+ "exclude": ["/index.html", "/style.css", "/script.js"]
+}
\ No newline at end of file
--- /dev/null
+export async function onRequestGet({ request, env }) {
+ const url = new URL(request.url);
+ const shortUrl = url.pathname.substring(1);
+ const fullUrl = await env.links.get(shortUrl);
+ if (fullUrl === null) {
+ return Response.redirect(url.origin, 302);
+ }
+ return Response.redirect(fullUrl, 302);
+}
await env.links.put(shortUrl, fullUrl);
return new Response(`Successfully created short URL: https://alu.bz/${shortUrl}`, { headers: { 'Content-Type': 'text/plain; charset=UTF-8' } });
}
-
-export async function onRequestGet({ request, env }) {
- const url = new URL(request.url);
- const shortUrl = url.search.substring(1);
- const fullUrl = await env.links.get(shortUrl);
- if (fullUrl === null) {
- return new Response('https://alu.bz');
- }
- return new Response(fullUrl);
-}
<link rel="icon" href="data:,">
<link rel="stylesheet" href="style.css">
<title>alu.bz</title>
- <script>
- (async () => {
- if (location.pathname !== '' && location.pathname !== '/') {
- location.replace(await fetch(`/api?${location.pathname.substring(1)}`).then(r => r.text()));
- }
- })();
- </script>
</head>
<body>