app structure, url redirects

This commit is contained in:
2026-10-06 11:04:09 -04:00
parent bb14cfa5a5
commit 0d647f0529
5 changed files with 70 additions and 2 deletions

22
src/lib/server/data.ts Normal file
View File

@@ -0,0 +1,22 @@
export const RegistryItems = [
{
id: 1,
name: "Item One",
url: "https://www.amazon.com/dp/B071VG5N9D?lv=shuf&social_share=cm_sw_r_cp_ud_dp_HNQ1V69T73P68F2Z4WZK&channelId=751&plpRedirect=mhFallback&th=1",
event: "wedding"
},
{
id: 2,
name: "Another Item",
url: "https://www.target.com",
event: "wedding"
},
];
export const AllowList = [
"https://amazon.com/",
"https://www.amazon.com/",
"https://a.co/",
"https://target.com/",
"https://www.target.com/"
]

View File

@@ -0,0 +1,10 @@
import { RegistryItems } from '#lib/server/data.ts';
import type { PageServerLoad } from './$types';
export const load: PageServerLoad = ({ params }) => {
const items = RegistryItems
.filter((i) => i.event === params.event)
.map(({ id, name }) => ({ id, name }));
return { event: params.event, items };
}

View File

@@ -0,0 +1,16 @@
<script lang="ts">
import type { PageData } from "./$types";
let { data }: { data: PageData } = $props();
</script>
<h1 class="text-3xl font-bold">Registry</h1>
<h2 class="text-lg">Items</h2>
<ul>
{#each data.items as item (item.id)}
<li>
<a href="/{data.event}/registry/{item.id}" target="_blank" class="underline text-blue-500">{item.name}</a>
</li>
{/each}
</ul>

View File

@@ -0,0 +1,19 @@
import { AllowList, RegistryItems } from "#lib/server/data.js";
import { error, redirect } from "@sveltejs/kit";
import type { RequestHandler } from './$types';
export const GET: RequestHandler = ({ params }) => {
const item = RegistryItems.find((i) => String(i.id) === params.item);
if (!item) {
error(404, "Registry Item not found");
};
const protocol = new URL(item.url).protocol;
if (protocol !== 'https:' && protocol !== 'http:') {
error(404, "Invalid Link");
};
redirect(302, item.url, { external: AllowList });
};