diff --git a/src/routes/post/[instance]/+page.ts b/src/routes/post/[instance]/+page.ts index f66640da..7a06cfe2 100644 --- a/src/routes/post/[instance]/+page.ts +++ b/src/routes/post/[instance]/+page.ts @@ -1,4 +1,5 @@ import { resolve } from '$app/paths' +import { env } from '$env/dynamic/public' import { profile } from '$lib/app/auth' import { error, redirect } from '@sveltejs/kit' @@ -7,7 +8,9 @@ export function load({ params }) { redirect( 302, resolve(`/post/[instance]/[id=integer]`, { - instance: encodeURIComponent(profile.current.instance.toLowerCase()), + instance: encodeURIComponent( + (env.PUBLIC_INSTANCE_URL || profile.current.instance).toLowerCase(), + ), id: params.instance, }), ) diff --git a/src/routes/post/[instance]/[id=integer]/+page.ts b/src/routes/post/[instance]/[id=integer]/+page.ts index e688a541..b7158177 100644 --- a/src/routes/post/[instance]/[id=integer]/+page.ts +++ b/src/routes/post/[instance]/[id=integer]/+page.ts @@ -1,4 +1,6 @@ +import { browser } from '$app/environment' import { goto } from '$app/navigation' +import { env } from '$env/dynamic/public' import { resolve } from '$app/paths' import { client } from '$lib/api/client.svelte' import { PiefedClient } from '$lib/api/piefed/adapter.js' @@ -51,7 +53,11 @@ async function findInFeed(id: '/' | '/c/[name]' | '/f/[id]', postId: string) { } export async function load({ params, url, route }) { - if (profile.current.instance != params.instance) { + // On the server profile.current.instance is the internal API address (PUBLIC_INTERNAL_INSTANCE), + // and goto() cannot run there; compare against the public instance and only redirect in the + // browser. + const here = env.PUBLIC_INSTANCE_URL?.toLowerCase() || profile.current.instance + if (browser && here != params.instance && profile.current.instance != params.instance) { goto(resolve('/post/[instance]/[id=integer]/confirm', params), { replaceState: true, })