|
| 1 | +# Base URLs, public URLs, paths & reverse proxies |
| 2 | + |
| 3 | +Since: `0.19.0-alpha.3`. |
| 4 | + |
| 5 | +Originally `trunk` had a single `--public-url`, which allowed to set the base URL of the hosted application. |
| 6 | +Plain and simple. This was a prefix for all URLs generated and acted as a base for `trunk serve`. |
| 7 | + |
| 8 | +Unfortunately, life isn't that simple and naming is hard. |
| 9 | + |
| 10 | +Today `trunk` was three paths: |
| 11 | + |
| 12 | +* The "public base URL": acting as a prefix for all generated URLs |
| 13 | +* The "serve base": acting as a scope/prefix for all things served by `trunk serve` |
| 14 | +* The "websocket base": acting as a base path for the auto-reload websocket |
| 15 | + |
| 16 | +All three can be configured, but there are reasonable defaults in place. By default, the serve base and websocket base |
| 17 | +default to the absolute path of the public base. The public base will have a slash appended if it doesn't have one. The |
| 18 | +public base can be one of: |
| 19 | + |
| 20 | +* Unset/nothing/default (meaning `/`) |
| 21 | +* An absolute URL (e.g. `http://domain/path/app`) |
| 22 | +* An absolute path (e.g. `/path/app`) |
| 23 | +* A relative path (e.g. `foo` or `./`) |
| 24 | + |
| 25 | +If the public base is an absolute URL, then the path of that URL will be used as serve and websocket base. If the public |
| 26 | +base is a relative path, then it will be turned into an absolute one. Both approaches might result in a dysfunctional |
| 27 | +application, based on your environment. There will be a warning on the console. However, by providing an explicit |
| 28 | +value using serve-base or ws-base, this can be fixed. |
| 29 | + |
| 30 | +Why is this necessary and when is it useful? It's mostly there to provide all the knobs/configurations for the case |
| 31 | +that weren't considered. The magic of public-url worked for many, but not for all. To support such cases, it |
| 32 | +is now possible to tweak all the settings, at the cost of more complexity. Having reasonable defaults should keep it |
| 33 | +simple for the simple cases. |
| 34 | + |
| 35 | +An example use case is a reverse proxy *in front* of `trunk serve`, which can't be configured to serve the trunk |
| 36 | +websocket at the location `trunk serve` expects it. Now, it is possible to have `--public-url` to choose the base when |
| 37 | +generating links, so that it looks correct when being served by the proxy. But also use `--serve-base /` to keep |
| 38 | +serving resource from the root. |
0 commit comments