forked from trunk-rs/trunk
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow more control over the different base URLs
This change introduced the idea of the three different base URLs: * The public base/common prefix, when generating links * The "serve base", when serving content using `trunk serve` * The "websocket base", where the auto-reload websocket connects to The sane default still is to use an absolute --public-url, defaulting to `/`. However, each of the URLs/bases can be overridden when necessary. Closes: trunk-rs#668, trunk-rs#626
- Loading branch information
Showing
16 changed files
with
480 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Trunk behind a reverse proxy | ||
|
||
The idea is to have `trunk serve` running behind a reverse proxy. This may be suitable for testing, | ||
but `trunk serve` is not intended to host your application. | ||
|
||
**NOTE:** This is different to using trunk's built in proxy, which by itself acts as a reverse proxy, allowing to | ||
access other endpoints using the endpoint served by `trunk serve`. | ||
|
||
**NOTE**: All commands are relative to this file. | ||
|
||
## Running the example | ||
|
||
As reverse proxy, we run an NGINX: | ||
|
||
```shell | ||
podman run --rm --network=host -ti -v $(pwd)/nginx.conf:/etc/nginx/nginx.conf:z docker.io/library/nginx:latest | ||
``` | ||
|
||
And then we serve the "vanilla" example using trunk: | ||
|
||
```shell | ||
trunk serve ../vanilla/Trunk.toml --public-url /my-app --serve-base / | ||
``` | ||
|
||
Or, using the development version: | ||
|
||
```shell | ||
cargo run --manifest-path=../../Cargo.toml -- serve --config ../vanilla/Trunk.toml --public-url /my-app --serve-base / | ||
``` | ||
|
||
## Trying it out | ||
|
||
When you go to <http://localhost:9090>, you will see the NGINX welcome screen. | ||
|
||
When you go to <http://localhost:9090/my-app/>, you will see the application served by `trunk`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
user nginx; | ||
worker_processes auto; | ||
|
||
error_log /var/log/nginx/error.log notice; | ||
pid /var/run/nginx.pid; | ||
|
||
events { | ||
worker_connections 1024; | ||
} | ||
|
||
http { | ||
include /etc/nginx/mime.types; | ||
default_type application/octet-stream; | ||
|
||
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | ||
'$status $body_bytes_sent "$http_referer" ' | ||
'"$http_user_agent" "$http_x_forwarded_for"'; | ||
|
||
access_log /var/log/nginx/access.log main; | ||
|
||
keepalive_timeout 65; | ||
|
||
server { | ||
listen 9090; | ||
|
||
location /my-app/.well-known/trunk/ws { | ||
proxy_pass http://localhost:8080/.well-known/trunk/ws; | ||
|
||
proxy_http_version 1.1; | ||
proxy_set_header Upgrade $http_upgrade; | ||
proxy_set_header Connection "Upgrade"; | ||
} | ||
location /my-app/ { | ||
proxy_pass http://localhost:8080/; | ||
|
||
# required for trunk to create correct URLs | ||
proxy_set_header Host $http_host; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.