Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Use runtime server config for deployment-specific values
Do not rely on build-time public environment variables for values that differ by deployed environment. Resolve deploy-specific origins and flags at runtime on the server boundary.
Bad example
| 1 | const previewOrigin = process.env.NEXT_PUBLIC_PREVIEW_ORIGIN; |
| 2 |
|
| 3 | export function getPreviewUrl(path: string) { |
| 4 | return new URL(path, previewOrigin).toString(); |
| 5 | } |
Explanation (EN)
This assumes the public environment value will match the deployed runtime, but public env values are often inlined at build time. The result can silently drift across environments and produce broken URLs or feature flags after deployment.
Objašnjenje (HR)
Ovo pretpostavlja da će javna env vrijednost odgovarati deployanom runtimeu, ali public env varijable često se ugrađuju već pri buildu. Rezultat može tiho odstupati među okruženjima i nakon deploya proizvesti neispravne URL-ove ili feature flagove.
Good example
| 1 | export function getPreviewUrl(path: string, requestOrigin: string) { |
| 2 | const baseUrl = process.env.PREVIEW_ORIGIN ?? requestOrigin; |
| 3 | return new URL(path, baseUrl).toString(); |
| 4 | } |
Explanation (EN)
The runtime boundary resolves the correct base URL for the actual deployed environment. This keeps deploy-specific behavior on the server side, where it can adapt safely across dev, staging, and production.
Objašnjenje (HR)
Runtime granica određuje ispravan base URL za stvarno deployano okruženje. Tako deploy-specifično ponašanje ostaje na serverskoj strani, gdje se može sigurno prilagoditi dev, staging i produkciji.
Notes (EN)
This applies to hostnames, preview origins, public asset bases, and feature flags that may differ between deployed environments.
Bilješke (HR)
Ovo se odnosi na hostnames, preview origine, baze za javne assete i feature flagove koji se mogu razlikovati među deployanim okruženjima.
Exceptions / Tradeoffs (EN)
Purely static public values that are intentionally identical in every build can stay as build-time public env vars.
Iznimke / Tradeoffi (HR)
Potpuno statične javne vrijednosti koje su namjerno iste u svakom buildu mogu ostati build-time public env varijable.