Skip to content

Commit ea262d2

Browse files
committed
http: documented 'baseUrl' option, the base URL fallback outside HTTP requests
1 parent 9d9cf07 commit ea262d2

4 files changed

Lines changed: 30 additions & 2 deletions

File tree

‎application/cs/bootstrapping.texy‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ V konfiguračních souborech můžete využít tyto parametry:
263263
- `%tempDir%` je absolutní cesta k adresáři pro dočasné soubory
264264
- `%vendorDir%` je absolutní cesta k adresáři, kam Composer instaluje knihovny
265265
- `%rootDir%` je absolutní cesta ke kořenovému adresáři projektu
266-
- `%baseUrl%` je absolutní URL ke kořenovému adresáři (dynamický parametr vyhodnocovaný za běhu)
266+
- `%baseUrl%` je absolutní URL ke kořenovému adresáři (dynamický parametr vyhodnocovaný za běhu; mimo HTTP požadavek se odvozuje z [http: baseUrl |http:configuration#Základní URL aplikace])
267267
- `%debugMode%` udává, zda je aplikace v debugovacím režimu
268268
- `%consoleMode%` udává, zda request přišel přes příkazovou řádku
269269

‎application/en/bootstrapping.texy‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ You can use these parameters in the configuration files:
263263
- `%tempDir%` is the absolute path to the directory for temporary files
264264
- `%vendorDir%` is the absolute path to the directory where Composer installs libraries
265265
- `%rootDir%` is the absolute path to the root directory of the project
266-
- `%baseUrl%` is the absolute URL to the root directory (a dynamic parameter resolved at runtime)
266+
- `%baseUrl%` is the absolute URL to the root directory (a dynamic parameter resolved at runtime; outside an HTTP request it is derived from [http: baseUrl |http:configuration#Application Base URL])
267267
- `%debugMode%` indicates whether the application is in debug mode
268268
- `%consoleMode%` indicates whether the request came through the command line
269269

‎http/cs/configuration.texy‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,20 @@ http:
122122
```
123123

124124

125+
Základní URL aplikace .{data-version:3.4.1}
126+
-------------------------------------------
127+
128+
Nette si zjišťuje adresu, na které aplikace běží, z HTTP požadavku, takže není potřeba nic nastavovat. Při spuštění z příkazové řádky (cron, úlohy, MCP server) ale žádný požadavek není a odvozené hodnoty jako `%baseUrl%`, odkazy z `LinkGenerator` nebo `$baseUrl` v šablonách by neměly odkud vzniknout. Pro tyto případy lze zadat základní URL aplikace:
129+
130+
```neon
131+
http:
132+
# použije se jen tehdy, když nelze adresu zjistit z požadavku
133+
baseUrl: https://example.com/ # (string) výchozí je nenastaveno
134+
```
135+
136+
Hodnota se uplatní pouze tehdy, když z prostředí nevzejde žádný host. Na webu má vždy přednost skutečný požadavek, takže stejná konfigurace funguje na localhostu i v produkci. URL musí být absolutní, včetně případného podadresáře (`https://example.com/eshop`).
137+
138+
125139
Session
126140
=======
127141

‎http/en/configuration.texy‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,20 @@ http:
122122
```
123123

124124

125+
Application Base URL .{data-version:3.4.1}
126+
------------------------------------------
127+
128+
Nette detects the address the application runs at from the HTTP request, so nothing needs to be configured. When run from the command line (cron, tasks, an MCP server) there is no request, and derived values such as `%baseUrl%`, links from `LinkGenerator` or `$baseUrl` in templates would have nothing to come from. For these cases you can specify the base URL of the application:
129+
130+
```neon
131+
http:
132+
# used only when the address cannot be detected from the request
133+
baseUrl: https://example.com/ # (string) defaults to not set
134+
```
135+
136+
The value applies only when the environment yields no host. On the web the actual request always takes precedence, so the same configuration works on localhost and in production. The URL must be absolute, including any subdirectory (`https://example.com/eshop`).
137+
138+
125139
Session
126140
=======
127141

0 commit comments

Comments
 (0)