Skip to content

About

React and FastAPI on one Gregale domain: the edge routes /api to FastAPI, so there is no CORS

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

React + FastAPI on one domain

Two independently deployable workloads. The browser loads React at / and sends relative /api requests to the same origin. A Gregale edge route serves those requests from FastAPI, without a Vite dev server in production.

Run locally

Python 3.13 and Node 24 are used in the Dockerfiles. Start the two development processes in separate terminals:

cd backend
python -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt
uvicorn main:app --port 8000
cd frontend
npm ci
npm run dev

Open Vite's local URL and click Check API. Vite only proxies /api in development. The production frontend serves the built bundle with npm run build and npm start, not vite preview.

Deploy the two workloads

Use unique app slugs in the same Gregale account or organization. These public demo endpoints only return synthetic data. Don't use open access on an existing app with private data.

WEB=choose-a-unique-web-slug
API=choose-a-unique-api-slug

gregale deploy --source=worktree --path frontend --name "$WEB"
gregale deploy --source=worktree --path backend --name "$API"
gregale app update "$WEB" --public-auth open --no-require-authn
gregale app update "$API" --public-auth open --no-require-authn

HOST="$WEB.gregale.app"
gregale edge rule create --app "$WEB" --kind route \
  --name react-fastapi-api --match-host "$HOST" --match-path '/api/**' \
  --route-target-slug "$API"

Open https://$HOST/ and click Check API. Expect Hello, Gregale, from FastAPI (api-v1). Check that /api/absent is a FastAPI JSON 404 and /assets/absent.js is a frontend 404. No API credential belongs in frontend code.

For a custom hostname, attach and verify it on the frontend, then create the same rule with that exact hostname. This example keeps the /api prefix in FastAPI; it does not use a rewrite. When finished, remove the disposable apps from your dashboard or restore bearer protection. Path routing is not an access control: an open API's own hostname can also be called directly.

Read the complete Gregale guide

About

React and FastAPI on one Gregale domain: the edge routes /api to FastAPI, so there is no CORS

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages