Files
kolaytercih/src/lib/app-url.ts
bilalgursen 951caa3c93
All checks were successful
Deploy / deploy (push) Successful in 8m39s
refactor(odeme): update environment variable usage and documentation
Replaced `NEXT_PUBLIC_APP_URL` with `APP_URL` in the payment processing logic to ensure proper runtime access. Updated related documentation to clarify the distinction between build-time and runtime environment variables, emphasizing the importance of using `APP_URL` for callback and webhook URLs. Adjusted references in the codebase to reflect this change, enhancing clarity and functionality in the payment flow.
2026-08-11 11:42:47 +03:00

28 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import "server-only";
/**
* Uygulamanın dışarıya görünen kök adresi — iyzico callbackUrl'i ve ödeme
* yönlendirmeleri buradan okunur.
*
* NEXT_PUBLIC_APP_URL BİLİNÇLİ OLARAK KULLANILMAZ: `NEXT_PUBLIC_*` değişkenleri
* Next tarafından build sırasında koda sabit string olarak gömülür, runtime'da
* okunmaz. Docker imajı build edilirken .env.production build katmanına hiç
* geçmediği için (.dockerignore `.env*` dosyalarını dışlıyor) o değişken build
* anında `undefined` olur ve fallback ("http://localhost:3000") imaja çakılırdı;
* compose `env_file` ile değeri container'a verse bile kod artık onu okumazdı.
* Sonuç: iyzico'ya localhost callback'i gidiyor ve initialize reddediliyordu.
*
* Buradaki değişkenler public önekli olmadığı için runtime'da okunur — env
* değişince yeniden build gerekmez.
*/
export function appUrl(): string {
const ham =
process.env.APP_URL ??
// Aynı origin'i zaten gösteriyor ve prod .env'inde mevcut; ayrı bir secret
// eklemeden doğru değere düşmek için ikinci sırada.
process.env.BETTER_AUTH_URL ??
"http://localhost:3000";
// Sondaki "/" ile birleştirmelerde "//paket" üretmemek için kırpılır.
return ham.replace(/\/+$/, "");
}