Skip to content

Commit de1eca3

Browse files
📝 Add a brief document on the built-in api proxy.
1 parent 925db00 commit de1eca3

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

gleam.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ internal_modules = ["lustre_dev_tools/*"]
1515
[documentation]
1616
pages = [
1717
{ title = "Static assets", path = "assets.html", source = "./pages/assets.md" },
18+
{ title = "Proxying requests", path = "proxying.html", source = "./pages/proxying.md" },
1819
{ title = "TOML reference", path = "toml-reference.html", source = "./pages/toml-reference.md" }
1920
]
2021

pages/proxying.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# API Proxying
2+
3+
Often you'll be developing your Lustre application alongside a separate backend
4+
app. This can cause some problems during development as you'll typically run into
5+
CORS issues when your Lustre app tries to make requests to your backend running
6+
on a different port.
7+
8+
To solve this, Lustre's development server includes support for proxying API
9+
requests to another server. This means your application code doesn't require
10+
environment-specific logic to determine where to send API requests to, instead
11+
it always hits a path like `/api/users` and the development server takes care of
12+
proxying that request to your backend.
13+
14+
## Configuration
15+
16+
To configure the API proxy, you'll need to add an entry to your `gleam.toml` file
17+
under the `tools.lustre.dev` section. The most common configuration looks something
18+
like this:
19+
20+
```toml
21+
[tools.lustre.dev]
22+
proxy = { from = "/api", to = "http://localhost:3000/api" }
23+
```
24+
25+
In this example, any requests made to paths starting with `/api` will be forwarded
26+
to `http://localhost:3000/api`. So a request to `/api/users` would be proxied to
27+
`http://localhost:3000/api/users`.

0 commit comments

Comments
 (0)