mirror of
https://codeberg.org/pronounscc/pronouns.cc.git
synced 2024-11-20 14:29:52 +01:00
feat: redirect /[username] to /@[username] if no page matches
This commit is contained in:
parent
56c0d40a11
commit
c60429d884
2 changed files with 20 additions and 0 deletions
19
frontend/src/routes/[username]/+page.server.ts
Normal file
19
frontend/src/routes/[username]/+page.server.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
import { ErrorCode, type APIError, type User } from "$lib/api/entities";
|
||||
import { apiFetch } from "$lib/api/fetch";
|
||||
import { error, redirect } from "@sveltejs/kit";
|
||||
|
||||
export const load = async ({ params }) => {
|
||||
try {
|
||||
const resp = await apiFetch<User>(`/users/${params.username}`, {
|
||||
method: "GET",
|
||||
});
|
||||
|
||||
throw redirect(303, `/@${resp.name}`);
|
||||
} catch (e) {
|
||||
if ((e as APIError).code === ErrorCode.UserNotFound) {
|
||||
throw error(404, (e as APIError).message);
|
||||
}
|
||||
|
||||
throw e;
|
||||
}
|
||||
};
|
1
frontend/src/routes/[username]/+page.svelte
Normal file
1
frontend/src/routes/[username]/+page.svelte
Normal file
|
@ -0,0 +1 @@
|
|||
<h1>Page not found</h1>
|
Loading…
Reference in a new issue