For me solution was like this:
// hooks.server.ts
import { building } from '$app/environment'
export const handle: Handle = async (p) => {
if(building){
// apply different logic here
} else {
const clientIp = p.event.getClientAddress()
}
}
more details: https://svelte.dev/docs/kit/$app-environment#building