From 0d647f05291a75c391fd97467f69cb1927f3f4a7 Mon Sep 17 00:00:00 2001 From: Brian Nelson Date: Tue, 6 Oct 2026 11:04:09 -0400 Subject: [PATCH] app structure, url redirects --- PROJECT.md | 5 +++-- src/lib/server/data.ts | 22 +++++++++++++++++++ .../(public)/[event]/registry/+page.server.ts | 10 +++++++++ .../(public)/[event]/registry/+page.svelte | 16 ++++++++++++++ .../[event]/registry/[item]/+server.ts | 19 ++++++++++++++++ 5 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 src/lib/server/data.ts create mode 100644 src/routes/(public)/[event]/registry/+page.server.ts create mode 100644 src/routes/(public)/[event]/registry/+page.svelte create mode 100644 src/routes/(public)/[event]/registry/[item]/+server.ts diff --git a/PROJECT.md b/PROJECT.md index 0853fc1..919d187 100644 --- a/PROJECT.md +++ b/PROJECT.md @@ -1,6 +1,6 @@ ## Status ### Last Completed -Started building out the app structure and putting in placeholders for unique rsvp token pages +Continued working on the app structure, more specifically started playing around with redirects and created an example registry to see how that would work. ### Next Up Continue to build on app structure @@ -36,4 +36,5 @@ For guests that are given a +1, there will be a placeholder name added as a Gues The `(app)` directory will be for all pages that need to have authentication. These will be the pages that the couple or planner will have access to. Publically facing pages will be in the `(public)` directory (things like the landing page and login page). This will also allow for a "wedding website" option that is publically accessible. -## Open Questions \ No newline at end of file +## Open Questions +I would like to have a general `AllowList` for the urls in the registry but give users the option to add more to the AllowList if they would like. \ No newline at end of file diff --git a/src/lib/server/data.ts b/src/lib/server/data.ts new file mode 100644 index 0000000..c4575f3 --- /dev/null +++ b/src/lib/server/data.ts @@ -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/" +] \ No newline at end of file diff --git a/src/routes/(public)/[event]/registry/+page.server.ts b/src/routes/(public)/[event]/registry/+page.server.ts new file mode 100644 index 0000000..9d07782 --- /dev/null +++ b/src/routes/(public)/[event]/registry/+page.server.ts @@ -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 }; +} \ No newline at end of file diff --git a/src/routes/(public)/[event]/registry/+page.svelte b/src/routes/(public)/[event]/registry/+page.svelte new file mode 100644 index 0000000..b1fc50c --- /dev/null +++ b/src/routes/(public)/[event]/registry/+page.svelte @@ -0,0 +1,16 @@ + + +

Registry

+

Items

+ + diff --git a/src/routes/(public)/[event]/registry/[item]/+server.ts b/src/routes/(public)/[event]/registry/[item]/+server.ts new file mode 100644 index 0000000..1d36d57 --- /dev/null +++ b/src/routes/(public)/[event]/registry/[item]/+server.ts @@ -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 }); +}; \ No newline at end of file