Skip to content

Commit 4ad84f7

Browse files
committed
removed URL loading page
- URL's now go directly to the destination
1 parent 8f94cf1 commit 4ad84f7

3 files changed

Lines changed: 27 additions & 176 deletions

File tree

src/routes/[slug]/+page.server.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/routes/[slug]/+page.svelte

Lines changed: 0 additions & 157 deletions
This file was deleted.

src/routes/[slug]/+server.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { createClient } from '@supabase/supabase-js'
2+
import { SUPABASE_KEY, SUPABASE_URL } from '$env/static/private';
3+
const supabase = createClient(SUPABASE_URL, SUPABASE_KEY);
4+
5+
/** @type {import('./$types').RequestHandler} */
6+
export const GET = async ({ params }) => {
7+
8+
const response = await supabase.from('links').select('original_url').eq('short_code', params.slug);
9+
10+
let url = null;
11+
if(response.data){
12+
if(response.data[0])
13+
url = response.data[0].original_url;
14+
}
15+
16+
if(url){
17+
return new Response(undefined, {
18+
status: 302,
19+
headers: { Location: url },
20+
})
21+
}else{
22+
return new Response(undefined, {
23+
status: 302,
24+
headers: { Location: '/' },
25+
})
26+
}
27+
}

0 commit comments

Comments
 (0)