fix: post pages 500 under SSR with PUBLIC_INTERNAL_INSTANCE
On the server profile.current.instance is the internal API address, so the post loader saw an instance mismatch and called goto(), which throws on the server. Compare against the public instance and only redirect in the browser. /post/<id> now redirects to the public instance instead of the internal one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011c5BZVwWdVLrdQi9htmuth
This commit is contained in:
1 parent
8e7c5be4c8
commit
f2429eb9ec
2 files changed
+11
-2
No files matched your search
@@ -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,
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -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,
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user