Skip to content
Snippets Groups Projects
Commit 93516fcd authored by Jiwon Sheen's avatar Jiwon Sheen
Browse files

edit short-url code

parent 3391f257
No related branches found
No related tags found
No related merge requests found
Pipeline #11116 passed
...@@ -50,6 +50,13 @@ export default { ...@@ -50,6 +50,13 @@ export default {
await env.KV_STORAGE.put(key, search.substr(1)); await env.KV_STORAGE.put(key, search.substr(1));
return new Response(`<a href=${protocol}//${host}/${key}>${protocol}//${host}/${key}</a>`, { headers: { 'Content-Type': 'text/html'}}); return new Response(`<a href=${protocol}//${host}/${key}>${protocol}//${host}/${key}</a>`, { headers: { 'Content-Type': 'text/html'}});
} }
if (pathname.length === 1) {
const destinationURL = await env.KV_STORAGE.get("*");
if (destinationURL === null)
return new Response("value not found", { status: 404 });
return Response.redirect(destinationURL, 301);
}
const destinationURL = await env.KV_STORAGE.get(pathname.substr(1)); const destinationURL = await env.KV_STORAGE.get(pathname.substr(1));
if (destinationURL === null) if (destinationURL === null)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment