Proxy Router
Example showing how to set up a router to proxy to another URL while serving files from a volume. This setup is commonly used to proxy to a frontend development server and its static files while serving a Wick API from the same root domain/IP.
This app configuration starts off with the common Application kind
and a name field.
kind: wick/app@v1
name: serve_http_component
Note: All HTTP routers must be configured with a
path
that acts as a simple filter to determine which router to execute. Routers are executed in top-down order. A router configured withpath: "/"
will match all traffic so should be defined at the end of the router configuration.
Proxy Routers require a Url resource that serves as the URL the proxy router will forward requests to.
resources:
- name: PROXY_URL
resource:
kind: wick/resource/url@v1
url: http://localhost:5173
The router configuration itself takes the url resource by the given name alongside a path to proxy from.
Note: The
path
can be stripped from the proxied path by specifyingstrip_path: true
.
routers:
- kind: wick/router/proxy@v1
path: /proxied
url: PROXY_URL
The full configuration is located at examples/http/proxy-router.wick. Run this application locally by cloning the wick repository and using wick run
(or cargo run -p wick-cli -- run
to run from source)
git clone https://github.com/candlecorp/wick && cd wick
wick run examples/http/proxy-router.wick
Complete Example
Note: Examples may require environment variables and execution from within the wick project’s root to access any local files.
The full example configuration is included below,
---
kind: wick/app@v1
name: serve_http_component
metadata:
description: |
Example showing how to set up a router to proxy to another URL while serving files from a volume.
This setup is commonly used to proxy to a frontend development server and its static files while serving a Wick API from the same root domain/IP.
version: 0.0.1
authors:
- 'Wick Maintainers'
vendors:
- 'Candle Corporation'
licenses:
- Apache-2.0
resources:
- name: http
resource:
kind: wick/resource/tcpport@v1
port: 8999
address: 0.0.0.0
- name: DIR
resource:
kind: wick/resource/volume@v1
path: '{{ ctx.env.PWD }}'
- name: PROXY_URL
resource:
kind: wick/resource/url@v1
url: http://localhost:5173
triggers:
- kind: wick/trigger/http@v1
resource: http
routers:
- kind: wick/router/proxy@v1
url: PROXY_URL
path: /proxied
- kind: wick/router/static@v1
path: /
volume: DIR