Tauri cors origins setup
Skill kjuhwa/skills-hub/skills/fastapi/tauri-cors-origins-setup
Allow a FastAPI backend to accept requests from the full range of Tauri webview origins on macOS, Windows, and Linux, plus Vite dev.From its SKILL.md
npx -y skills add kjuhwa/skills-hub --skill tauri-cors-origins-setupAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
2.6 KB, 533 tokens by cl100k_base, as published. Nobody here has run it
Tauri CORS origins setup
When to use
A FastAPI sidecar talks to a Tauri webview in dev and in production across all three desktop platforms. You keep seeing CORS errors that only reproduce on one OS, or only in dev.
Steps
- Seed the allowed origins list with dev + every Tauri webview origin form:
http://localhost:5173andhttp://127.0.0.1:5173(Vite dev server)http://localhost:<server_port>andhttp://127.0.0.1:<server_port>for the backend's own port, in case the frontend is embedded behind ittauri://localhost(Tauri on macOS)https://tauri.localhost(Tauri on Windows/Linux in most versions)http://tauri.localhost(Tauri on Windows in some builds)
- Accept runtime extension via an env var like
VOICEBOX_CORS_ORIGINS="https://..., https://...". Split on comma, strip each entry, and extend the default list. This lets power users run with a reverse proxy or remote access without a rebuild. - Install
CORSMiddlewarewithallow_origins=the computed list,allow_credentials=True,allow_methods=["*"],allow_headers=["*"]. Because Tauri origins are not wildcardable (scheme varies), do NOT useallow_origins=["*"]— wildcards are incompatible withallow_credentials=Trueper spec. - Keep the CORS setup in a single
_configure_cors(app)helper invoked by the app factory. New dev ports or platform quirks land in one place.
Counter / Caveats
- The three
tauri.localhostvariants are all real — different Tauri versions and platforms use different schemes. Don't drop any of them "to clean up" until you've tested the matrix. allow_origins=["*"]withallow_credentials=Truesilently disables credentials in modern browsers. Use the explicit list even if it feels long.- If you add a new origin via the env var on production, remember it must include the scheme (
https://example.com, notexample.com). - In dev, Vite's port may change if 5173 is taken; consider adding 5174/5175 or reading Vite config to extend the list.
Source references: backend/app.py (_configure_cors).
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.