Skip to content

Commit 7db301e

Browse files
Merge pull request #957 from contributor (Netlify Backend Proxy)
2 parents 041dd21 + 84e428f commit 7db301e

3 files changed

Lines changed: 54 additions & 1 deletion

File tree

‎README.md‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,48 @@ It feels like:
103103
| Storage | LocalStorage |
104104

105105
---
106+
## 🚀 Backend Deployment & BACKEND_URL Setup
106107

108+
> ⚠️ The frontend is deployed on Netlify, but the Flask backend is **not yet deployed**.
109+
> Google Sign-In and all AI features require the backend to be running.
110+
111+
### Why is this needed?
112+
When a user clicks "Sign in with Google", the browser sends a request to `/api/v1/auth/google`.
113+
Netlify needs to know where to forward that request, that's what `BACKEND_URL` is for.
114+
Without it, Netlify has no rule for `/api/v1/*` and shows a 404 error.
115+
116+
### Step 1 — Deploy the Flask backend
117+
118+
You can deploy the backend (located in the `/backend` folder) to either:
119+
120+
| Platform | Free Tier | Docs |
121+
|---|---|---|
122+
| [Render](https://render.com) | ✅ Yes | [Render Python Docs](https://render.com/docs/deploy-flask) |
123+
| [Railway](https://railway.app) | ✅ Yes | [Railway Docs](https://docs.railway.app) |
124+
125+
After deploying, you'll get a public URL like:
126+
https://your-app.onrender.com
127+
128+
### Step 2 — Set BACKEND_URL in Netlify
129+
130+
1. Go to [Netlify Dashboard](https://app.netlify.com)
131+
2. Open your site → **Site Configuration → Environment Variables**
132+
3. Click **Add a variable**
133+
4. Set:
134+
- **Key:** `BACKEND_URL`
135+
- **Value:** `https://your-app.onrender.com` *(no trailing slash)*
136+
5. Click **Save**
137+
138+
### Step 3 — Redeploy the Netlify site
139+
140+
After setting the variable:
141+
1. Go to **Deploys** tab in your Netlify dashboard
142+
2. Click **Trigger deploy → Deploy site**
143+
3. This reruns `build_netlify.py`, which picks up `BACKEND_URL` and adds the proxy rule to `_redirects`
144+
145+
After this, "Sign in with Google" will correctly reach the Flask backend. ✅
146+
147+
---
107148
## 🧠 System Architecture
108149

109150
```mermaid

‎build_netlify.py‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,16 @@ def build_html() -> None:
5757

5858

5959
def write_clean_route_redirects() -> None:
60-
redirects = [
60+
redirects = []
61+
62+
# if BACKEND_URL is set in Netlify's environment variables,
63+
# proxy all /api/v1/* requests to the Flask backend.
64+
# without this, Netlify has no rule for /api/v1/ and shows a 404.
65+
backend_url = os.getenv("BACKEND_URL", "").strip().rstrip("/")
66+
if backend_url:
67+
redirects.append(f"/api/v1/* {backend_url}/api/v1/:splat 200")
68+
69+
redirects += [
6170
"/app /app.html 200",
6271
"/chat /chat.html 200",
6372
"/auth /auth.html 200",

‎netlify.toml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ functions = "netlify/functions"
55

66
[build.environment]
77
PYTHON_VERSION = "3.10"
8+
# BACKEND_URL is intentionally not set here: never commit secrets to the repo.
9+
# Set it in: Netlify Dashboard → Site Configuration → Environment Variables
10+
# Example value: https://your-app.onrender.com
811

912
[[headers]]
1013
for = "/*.gltf"

0 commit comments

Comments
 (0)