refactor(odeme): update environment variable usage and documentation
All checks were successful
Deploy / deploy (push) Successful in 8m39s

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.
This commit is contained in:
bilalgursen
2026-08-11 11:42:47 +03:00
parent d03ba91bf0
commit 951caa3c93
6 changed files with 47 additions and 9 deletions

27
src/lib/app-url.ts Normal file
View File

@@ -0,0 +1,27 @@
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(/\/+$/, "");
}