HTTP Routing with Backend
Goal
After this guide, you can verify these 3 points:
exec://...handler does both "start process + forward traffic", suitable for single-container backend bootstrap.http://...handler only forwards traffic and does not start processes, suitable for existing independent services.- You understand default protection, minimal
application.public_pathexposure, and why backend data should go to/lzcapp/var.
Prerequisites
- You completed Hello World in 5 Minutes.
lzc-cli box defaultpoints to your target microservice.curlis available on your machine (optional verification).
Steps
1. Create a backend template project
lzc-cli project create hello-api -t todolist-golangAt app id prompt, press Enter for default id or provide your own. Then enter project dir:
cd hello-api2. Deploy first and verify default exec handler
lzc-cli project deploy
lzc-cli project infoBy default, project commands prefer lzc-build.dev.yml and print the active Build config. Use --release if you want to operate on lzc-build.yml.
Before continuing, ensure lzc-cli project info includes Project app is running.
If still starting, wait a few seconds and rerun lzc-cli project info.
Open Target URL in browser and complete login. In browser Console, run:
fetch('/api/health').then((r) => r.json()).then(console.log);
fetch('/api/todos').then((r) => r.json()).then(console.log);Expected:
/api/healthreturns{"status":"ok"}./api/todosreturns anitemslist (usually empty initially).
Notes:
- Default route is
/=exec://3000,/app/run.sh. - This runs
/app/run.shand forwards traffic to127.0.0.1:3000. - That is the core behavior of
exechandler: start + forward.
3. Add a third-party service to demonstrate http handler
Edit lzc-manifest.yml. Keep default exec route and add /inspect/ route with whoami service:
application:
image: embed:app-runtime
routes:
- /inspect/=http://whoami:80/
- /=exec://3000,/app/run.sh
services:
whoami:
image: registry.lazycat.cloud/traefik/whoamiNotes:
whoamiis a real third-party service used as a clearhttpforwarding target./inspect/goes tohttp://whoami:80/and does not trigger/app/run.sh.- Keep
"/=exec://..."unchanged so original Todo behavior remains. - Put
/inspect/before"/="to avoid broader rule matching first.
4. Deploy and verify http handler
lzc-cli project deploy
lzc-cli project infoIn logged-in browser Console:
fetch('/inspect/').then((r) => r.text()).then(console.log);Expected: output includes whoami request info (Hostname, RemoteAddr, Headers, etc.).
5. (Optional) Configure application.public_path and test with curl
By default, HTTPS paths are protected by login state. Direct unauthenticated curl is expected to be blocked.
If you want to expose health check path, add in lzc-manifest.yml:
application:
public_path:
- /api/healthRedeploy and verify:
lzc-cli project deploy
lzc-cli project info
curl "<Target URL>/api/health"Only expose minimal paths in public_path.
6. Check Todolist data directory (/lzcapp/var)
First add 1-2 todo items in app UI so data files are created.
Enter app container:
lzc-cli project exec -s app /bin/shThen run inside container:
ls -la /lzcapp/varFor Todolist-like backend data, files should be in /lzcapp/var (for example /lzcapp/var/todos.json).
Important: only content under /lzcapp/var/ persists across app restarts.
Verification
Pass conditions:
project infoshowsCurrent version deployed: yes./api/healthreturnsstatus: "ok"./inspect/returns whoami request info.- Using
project exec, you can verify Todolist persistent path under/lzcapp/var.
Troubleshooting
1. /inspect/ returns 404 or 502
Check in order:
- Route is exactly
/inspect/=http://whoami:80/. - This route is before
"/=". services.whoami.imageisregistry.lazycat.cloud/traefik/whoami.- Run
lzc-cli project log -s whoami -f.
2. curl <Target URL>/api/health is blocked or redirected to login
Reason: default protection is enabled.
Fix:
- Verify via logged-in browser with
fetch('/api/health'). - Or add
application.public_pathand redeploy.
3. Not sure where Todolist data should be stored
Use /lzcapp/var; only this path persists across restarts.
4. No visible change after deploy
lzc-cli project deploy
lzc-cli project infoEnsure Current version deployed: yes.
Next
Continue with: How LPK Works