Spaces:
Sleeping
Sleeping
saadrizvi09
commited on
Commit
Β·
ad21741
1
Parent(s):
4cca173
Add frontend HF Space connection guide and env configs
Browse files- BACKEND_DEPLOYMENT_HF.md +121 -8
- FRONTEND_HF_CONNECTION.md +271 -0
- frontend/.env.example +12 -2
- frontend/.env.production.hf +4 -0
BACKEND_DEPLOYMENT_HF.md
CHANGED
|
@@ -68,14 +68,127 @@ git remote add space https://huggingface.co/spaces/YOUR-USERNAME/wagerkit-backen
|
|
| 68 |
git push space main
|
| 69 |
```
|
| 70 |
|
| 71 |
-
#### **Method 2: GitHub Sync** (Automatic Updates)
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
Now every push to GitHub main branch auto-deploys to HF Spaces! π
|
| 81 |
|
|
|
|
| 68 |
git push space main
|
| 69 |
```
|
| 70 |
|
| 71 |
+
#### **Method 2: GitHub Sync** (Automatic Updates) β Recommended
|
| 72 |
+
|
| 73 |
+
**This method auto-deploys every time you push to GitHub!**
|
| 74 |
+
|
| 75 |
+
##### **Detailed Steps:**
|
| 76 |
+
|
| 77 |
+
1. **Create the Space first** (complete Step 2 above)
|
| 78 |
+
|
| 79 |
+
2. **Navigate to your Space's Settings:**
|
| 80 |
+
- Go to your Space page: `https://huggingface.co/spaces/YOUR-USERNAME/wagerkit-backend`
|
| 81 |
+
- Look at the top menu bar (same row as "App", "Files", "Community")
|
| 82 |
+
- Click **"Settings"** (gear icon βοΈ)
|
| 83 |
+
|
| 84 |
+
3. **Find the Repository/Sync Section:**
|
| 85 |
+
|
| 86 |
+
**Option A - If you see "Repository" or "Sync" tab:**
|
| 87 |
+
- In Settings sidebar, look for **"Repository"** or **"Sync with GitHub"**
|
| 88 |
+
- Click it
|
| 89 |
+
- You'll see a button **"Link to GitHub"** or **"Connect to GitHub"**
|
| 90 |
+
|
| 91 |
+
**Option B - If you see "Factory Reboot":**
|
| 92 |
+
- Some HF Spaces interfaces show **"Factory Reboot"** instead
|
| 93 |
+
- Look for **"Source code"** section
|
| 94 |
+
- Click **"Link to GitHub repository"**
|
| 95 |
+
|
| 96 |
+
**Option C - If you don't see any GitHub options:**
|
| 97 |
+
- This is normal for newly created Spaces
|
| 98 |
+
- **Use Method 1 (Direct Push) first** - see below
|
| 99 |
+
- After first push, the GitHub sync option will appear
|
| 100 |
+
|
| 101 |
+
4. **Connect to GitHub:**
|
| 102 |
+
- Click **"Link to GitHub"** or **"Connect repository"**
|
| 103 |
+
- A popup opens asking for GitHub authorization
|
| 104 |
+
- Click **"Authorize Hugging Face"** (you may need to sign in to GitHub)
|
| 105 |
+
- HF will request permissions to read your repositories
|
| 106 |
+
|
| 107 |
+
5. **Select Your Repository:**
|
| 108 |
+
- After authorization, you'll see a dropdown or list
|
| 109 |
+
- Search for or select: `YOUR-GITHUB-USERNAME/demo` (or your repo name)
|
| 110 |
+
- **Important:** Make sure the repo is **public** or you've granted HF access to private repos
|
| 111 |
+
|
| 112 |
+
6. **Configure Branch:**
|
| 113 |
+
- **Branch to sync:** Select `main` (or `master` if that's your default)
|
| 114 |
+
- **Path in repository:** Leave blank (HF will use root `/`)
|
| 115 |
+
- **Dockerfile path:** Should auto-detect `Dockerfile` at root
|
| 116 |
+
- If you kept `Dockerfile.backend`, set path to: `Dockerfile.backend`
|
| 117 |
+
|
| 118 |
+
7. **Save and Sync:**
|
| 119 |
+
- Click **"Link repository"** or **"Connect"**
|
| 120 |
+
- HF will immediately pull from GitHub and start building
|
| 121 |
+
- You'll see build logs in the **Logs** tab
|
| 122 |
+
|
| 123 |
+
##### **Verification:**
|
| 124 |
+
|
| 125 |
+
Once connected, you should see:
|
| 126 |
+
- β
In Settings β Repository: Shows your GitHub repo URL
|
| 127 |
+
- β
Every `git push origin main` triggers automatic rebuild
|
| 128 |
+
- β
Space page shows "Connected to: github.com/YOUR-USERNAME/demo"
|
| 129 |
+
|
| 130 |
+
##### **β οΈ Troubleshooting: Can't Find Repository Settings?**
|
| 131 |
+
|
| 132 |
+
**Issue 1: "Settings has no Repository tab"**
|
| 133 |
+
|
| 134 |
+
**Solution:** The Space hasn't been initialized yet. Do Method 1 first:
|
| 135 |
+
```powershell
|
| 136 |
+
# Add HF Space as remote and push once
|
| 137 |
+
git remote add space https://huggingface.co/spaces/YOUR-USERNAME/wagerkit-backend
|
| 138 |
+
git push space main
|
| 139 |
+
```
|
| 140 |
+
After this first push, go back to Settings and the Repository/Sync option will appear.
|
| 141 |
+
|
| 142 |
+
---
|
| 143 |
+
|
| 144 |
+
**Issue 2: "Authorization keeps failing"**
|
| 145 |
+
|
| 146 |
+
**Solution:**
|
| 147 |
+
1. Go to GitHub β Settings β Applications β Authorized OAuth Apps
|
| 148 |
+
2. Find "Hugging Face" and click it
|
| 149 |
+
3. Click **"Revoke access"**
|
| 150 |
+
4. Go back to HF Spaces and try connecting again (it will re-authorize)
|
| 151 |
+
|
| 152 |
+
---
|
| 153 |
+
|
| 154 |
+
**Issue 3: "Repository is not found"**
|
| 155 |
+
|
| 156 |
+
**Solution:**
|
| 157 |
+
- Ensure your GitHub repo is **public**, OR
|
| 158 |
+
- In HF authorization screen, grant access to the specific private repository
|
| 159 |
+
- Repo must already exist on GitHub before connecting
|
| 160 |
+
|
| 161 |
+
---
|
| 162 |
+
|
| 163 |
+
**Issue 4: "HF keeps using old code"**
|
| 164 |
+
|
| 165 |
+
**Solution:**
|
| 166 |
+
1. In Space Settings, look for **"Factory Reboot"**
|
| 167 |
+
2. Click **"Reboot Space"** to force rebuild from GitHub
|
| 168 |
+
3. Or push an empty commit to trigger rebuild:
|
| 169 |
+
```powershell
|
| 170 |
+
git commit --allow-empty -m "Trigger HF rebuild"
|
| 171 |
+
git push origin main
|
| 172 |
+
```
|
| 173 |
+
|
| 174 |
+
---
|
| 175 |
+
|
| 176 |
+
##### **Alternative: Use Method 1 First, Then Connect**
|
| 177 |
+
|
| 178 |
+
If you can't find the GitHub sync option:
|
| 179 |
+
|
| 180 |
+
```powershell
|
| 181 |
+
# Step 1: Push directly to HF Space first
|
| 182 |
+
git remote add space https://huggingface.co/spaces/YOUR-USERNAME/wagerkit-backend
|
| 183 |
+
git push space main
|
| 184 |
+
|
| 185 |
+
# Step 2: After first successful deployment, go to Settings
|
| 186 |
+
# Now the "Repository" or "Sync" tab should appear
|
| 187 |
+
# Follow steps above to link to GitHub
|
| 188 |
+
|
| 189 |
+
# Step 3: From now on, only push to GitHub
|
| 190 |
+
git push origin main # This auto-deploys to HF Space
|
| 191 |
+
```
|
| 192 |
|
| 193 |
Now every push to GitHub main branch auto-deploys to HF Spaces! π
|
| 194 |
|
FRONTEND_HF_CONNECTION.md
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# π Connect Frontend to Hugging Face Backend
|
| 2 |
+
|
| 3 |
+
Your backend is deployed at: **https://saadrizvi09-wagerkit.hf.space**
|
| 4 |
+
|
| 5 |
+
This guide shows how to configure your **local frontend** to connect to your **HF Space backend**.
|
| 6 |
+
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
## π― Quick Setup
|
| 10 |
+
|
| 11 |
+
### **Option 1: Use Pre-configured Production Env** (Easiest)
|
| 12 |
+
|
| 13 |
+
```powershell
|
| 14 |
+
# Copy the production HF config to your local env
|
| 15 |
+
cd c:\demo\frontend
|
| 16 |
+
Copy-Item .env.production.hf .env.local -Force
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
### **Option 2: Edit Manually**
|
| 20 |
+
|
| 21 |
+
Open `c:\demo\frontend\.env.local` and change:
|
| 22 |
+
|
| 23 |
+
```dotenv
|
| 24 |
+
# FROM (local backend):
|
| 25 |
+
NEXT_PUBLIC_API_URL=http://localhost:3001/api
|
| 26 |
+
|
| 27 |
+
# TO (HF Space backend):
|
| 28 |
+
NEXT_PUBLIC_API_URL=https://saadrizvi09-wagerkit.hf.space/api
|
| 29 |
+
```
|
| 30 |
+
|
| 31 |
+
---
|
| 32 |
+
|
| 33 |
+
## π Start Frontend
|
| 34 |
+
|
| 35 |
+
After changing the env variable:
|
| 36 |
+
|
| 37 |
+
```powershell
|
| 38 |
+
cd c:\demo\frontend
|
| 39 |
+
npm run dev
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
Open: http://localhost:3000
|
| 43 |
+
|
| 44 |
+
Your frontend will now fetch data from the HF Space backend! π
|
| 45 |
+
|
| 46 |
+
---
|
| 47 |
+
|
| 48 |
+
## π§ͺ Test the Connection
|
| 49 |
+
|
| 50 |
+
### **1. Test Backend Directly**
|
| 51 |
+
|
| 52 |
+
First verify your HF Space backend is running:
|
| 53 |
+
|
| 54 |
+
**In browser:**
|
| 55 |
+
```
|
| 56 |
+
https://saadrizvi09-wagerkit.hf.space/api/markets
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
**In PowerShell:**
|
| 60 |
+
```powershell
|
| 61 |
+
$url = "https://saadrizvi09-wagerkit.hf.space/api/markets"
|
| 62 |
+
Invoke-RestMethod -Uri $url | ConvertTo-Json -Depth 3
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
You should see 3 markets (Election, BTC, CPI).
|
| 66 |
+
|
| 67 |
+
---
|
| 68 |
+
|
| 69 |
+
### **2. Test Frontend with HF Backend**
|
| 70 |
+
|
| 71 |
+
1. Update `.env.local` to use HF Space URL (see above)
|
| 72 |
+
2. Restart frontend: `npm run dev`
|
| 73 |
+
3. Open http://localhost:3000/dashboard
|
| 74 |
+
4. Cards should show data from HF Space backend
|
| 75 |
+
|
| 76 |
+
**Check Network Tab (F12 β Network):**
|
| 77 |
+
- Look for requests to `https://saadrizvi09-wagerkit.hf.space/api/markets`
|
| 78 |
+
- Status should be `200 OK`
|
| 79 |
+
|
| 80 |
+
---
|
| 81 |
+
|
| 82 |
+
## π§ Troubleshooting
|
| 83 |
+
|
| 84 |
+
### **Issue 1: CORS Error**
|
| 85 |
+
|
| 86 |
+
**Error:** `Access-Control-Allow-Origin header is missing`
|
| 87 |
+
|
| 88 |
+
**Solution:** The backend's CORS is already configured to allow HF Spaces domains. If you still see this error:
|
| 89 |
+
|
| 90 |
+
1. Check backend logs in HF Space
|
| 91 |
+
2. Verify the backend is running (green status dot)
|
| 92 |
+
3. Backend's `main.ts` already has:
|
| 93 |
+
```typescript
|
| 94 |
+
origin: [
|
| 95 |
+
'http://localhost:3000',
|
| 96 |
+
'http://localhost:7860',
|
| 97 |
+
/\.hf\.space$/, // Allows all HF Spaces
|
| 98 |
+
]
|
| 99 |
+
```
|
| 100 |
+
|
| 101 |
+
---
|
| 102 |
+
|
| 103 |
+
### **Issue 2: Network Error / Connection Refused**
|
| 104 |
+
|
| 105 |
+
**Solutions:**
|
| 106 |
+
1. **Check backend status:** Go to https://huggingface.co/spaces/saadrizvi09/wagerkit
|
| 107 |
+
- Status should be π’ Running
|
| 108 |
+
- If π‘ Building, wait 5-10 mins
|
| 109 |
+
- If π΄ Error, check Logs tab
|
| 110 |
+
2. **Verify URL:** Make sure env has `/api` at the end
|
| 111 |
+
3. **Clear browser cache:** Hard refresh (Ctrl+Shift+R)
|
| 112 |
+
|
| 113 |
+
---
|
| 114 |
+
|
| 115 |
+
### **Issue 3: Empty Dashboard**
|
| 116 |
+
|
| 117 |
+
**If cards show "Processing..." forever:**
|
| 118 |
+
|
| 119 |
+
1. **Check job status:**
|
| 120 |
+
```powershell
|
| 121 |
+
Invoke-RestMethod -Uri "https://saadrizvi09-wagerkit.hf.space/api/markets/jobs/status"
|
| 122 |
+
```
|
| 123 |
+
|
| 124 |
+
2. **Manually refresh a market:**
|
| 125 |
+
```powershell
|
| 126 |
+
Invoke-RestMethod -Method POST -Uri "https://saadrizvi09-wagerkit.hf.space/api/markets/us_election_2024_winner/refresh"
|
| 127 |
+
```
|
| 128 |
+
|
| 129 |
+
3. **Check backend logs:** HF Space β Logs tab
|
| 130 |
+
- Look for BullMQ/Redis errors
|
| 131 |
+
- Verify Redis started successfully
|
| 132 |
+
|
| 133 |
+
---
|
| 134 |
+
|
| 135 |
+
### **Issue 4: Slow Response**
|
| 136 |
+
|
| 137 |
+
HF Spaces free tier has limited CPU. First requests may be slow (cold start).
|
| 138 |
+
|
| 139 |
+
**Solutions:**
|
| 140 |
+
- Wait 10-20 seconds for first load
|
| 141 |
+
- Subsequent requests should be faster
|
| 142 |
+
- Upgrade to HF Spaces CPU Medium for better performance
|
| 143 |
+
|
| 144 |
+
---
|
| 145 |
+
|
| 146 |
+
## π Deploy Frontend Separately
|
| 147 |
+
|
| 148 |
+
If you want to deploy the frontend elsewhere (Vercel, Netlify, etc.):
|
| 149 |
+
|
| 150 |
+
### **For Vercel:**
|
| 151 |
+
|
| 152 |
+
1. Push your code to GitHub (already done β
)
|
| 153 |
+
2. Go to https://vercel.com/new
|
| 154 |
+
3. Import: `saadrizvi09/wager-kit-demo`
|
| 155 |
+
4. **Root Directory:** `frontend`
|
| 156 |
+
5. **Environment Variables:**
|
| 157 |
+
```
|
| 158 |
+
NEXT_PUBLIC_API_URL=https://saadrizvi09-wagerkit.hf.space/api
|
| 159 |
+
```
|
| 160 |
+
6. Deploy
|
| 161 |
+
|
| 162 |
+
Your frontend will be at: `https://your-project.vercel.app`
|
| 163 |
+
|
| 164 |
+
---
|
| 165 |
+
|
| 166 |
+
### **For Netlify:**
|
| 167 |
+
|
| 168 |
+
1. Go to https://app.netlify.com/start
|
| 169 |
+
2. Connect to GitHub repo: `saadrizvi09/wager-kit-demo`
|
| 170 |
+
3. **Base directory:** `frontend`
|
| 171 |
+
4. **Build command:** `npm run build`
|
| 172 |
+
5. **Publish directory:** `.next`
|
| 173 |
+
6. **Environment Variables:**
|
| 174 |
+
```
|
| 175 |
+
NEXT_PUBLIC_API_URL=https://saadrizvi09-wagerkit.hf.space/api
|
| 176 |
+
```
|
| 177 |
+
7. Deploy
|
| 178 |
+
|
| 179 |
+
---
|
| 180 |
+
|
| 181 |
+
### **For Another HF Space (Full-Stack):**
|
| 182 |
+
|
| 183 |
+
If you want both frontend + backend in one HF Space:
|
| 184 |
+
|
| 185 |
+
1. Create new Space with Docker SDK
|
| 186 |
+
2. Use the original `Dockerfile.fullstack` instead
|
| 187 |
+
3. Push code
|
| 188 |
+
4. Frontend will be at: `https://your-space.hf.space`
|
| 189 |
+
|
| 190 |
+
---
|
| 191 |
+
|
| 192 |
+
## π Environment Variable Reference
|
| 193 |
+
|
| 194 |
+
| Environment | API URL | Use Case |
|
| 195 |
+
|-------------|---------|----------|
|
| 196 |
+
| **Local Dev (both)** | `http://localhost:3001/api` | Backend + Frontend on localhost |
|
| 197 |
+
| **Frontend β HF Backend** | `https://saadrizvi09-wagerkit.hf.space/api` | Local frontend, deployed backend |
|
| 198 |
+
| **Vercel/Netlify β HF Backend** | `https://saadrizvi09-wagerkit.hf.space/api` | Deployed frontend, HF backend |
|
| 199 |
+
| **Docker Full-Stack** | `/api` | Both in same container |
|
| 200 |
+
|
| 201 |
+
---
|
| 202 |
+
|
| 203 |
+
## π Switch Between Backends
|
| 204 |
+
|
| 205 |
+
You can easily switch between local and HF backends:
|
| 206 |
+
|
| 207 |
+
### **Use Local Backend:**
|
| 208 |
+
```powershell
|
| 209 |
+
cd c:\demo\frontend
|
| 210 |
+
Copy-Item .env.local.example .env.local
|
| 211 |
+
# Edit to: NEXT_PUBLIC_API_URL=http://localhost:3001/api
|
| 212 |
+
npm run dev
|
| 213 |
+
```
|
| 214 |
+
|
| 215 |
+
### **Use HF Space Backend:**
|
| 216 |
+
```powershell
|
| 217 |
+
cd c:\demo\frontend
|
| 218 |
+
Copy-Item .env.production.hf .env.local -Force
|
| 219 |
+
npm run dev
|
| 220 |
+
```
|
| 221 |
+
|
| 222 |
+
### **Restart is Required:**
|
| 223 |
+
You MUST restart the frontend dev server after changing `.env.local`:
|
| 224 |
+
```powershell
|
| 225 |
+
# Stop: Ctrl+C
|
| 226 |
+
# Start:
|
| 227 |
+
npm run dev
|
| 228 |
+
```
|
| 229 |
+
|
| 230 |
+
---
|
| 231 |
+
|
| 232 |
+
## β
Verify Connection
|
| 233 |
+
|
| 234 |
+
After setup, check:
|
| 235 |
+
|
| 236 |
+
1. β
HF Backend is running (green dot)
|
| 237 |
+
2. β
Frontend `.env.local` has HF Space URL
|
| 238 |
+
3. β
Frontend restarted after env change
|
| 239 |
+
4. β
Dashboard loads market cards with data
|
| 240 |
+
5. β
Network tab shows requests to HF Space URL
|
| 241 |
+
|
| 242 |
+
---
|
| 243 |
+
|
| 244 |
+
## π Your Setup
|
| 245 |
+
|
| 246 |
+
**Backend (HF Space):**
|
| 247 |
+
- URL: https://saadrizvi09-wagerkit.hf.space
|
| 248 |
+
- API: https://saadrizvi09-wagerkit.hf.space/api/markets
|
| 249 |
+
- Status: Check at https://huggingface.co/spaces/saadrizvi09/wagerkit
|
| 250 |
+
|
| 251 |
+
**Frontend (Local):**
|
| 252 |
+
- URL: http://localhost:3000
|
| 253 |
+
- Connected to: HF Space backend (after env change)
|
| 254 |
+
|
| 255 |
+
**GitHub:**
|
| 256 |
+
- Repo: https://github.com/saadrizvi09/wager-kit-demo
|
| 257 |
+
|
| 258 |
+
---
|
| 259 |
+
|
| 260 |
+
## π‘ Pro Tips
|
| 261 |
+
|
| 262 |
+
β
**Keep `.env.local` in gitignore** - Never commit API keys
|
| 263 |
+
β
**Use `.env.example`** - Document what variables are needed
|
| 264 |
+
β
**Test backend first** - Always verify backend works before connecting frontend
|
| 265 |
+
β
**Check CORS** - Backend must allow your frontend's origin
|
| 266 |
+
β
**Monitor HF logs** - Watch for errors when frontend makes requests
|
| 267 |
+
β
**Use environment variables** - Never hardcode URLs in components
|
| 268 |
+
|
| 269 |
+
---
|
| 270 |
+
|
| 271 |
+
**Your frontend is now ready to connect to the HF Space backend! π**
|
frontend/.env.example
CHANGED
|
@@ -1,6 +1,16 @@
|
|
| 1 |
# Frontend Environment Variables
|
| 2 |
|
| 3 |
# API URL - Backend API endpoint
|
| 4 |
-
#
|
| 5 |
-
|
|
|
|
| 6 |
NEXT_PUBLIC_API_URL=http://localhost:3001/api
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# Frontend Environment Variables
|
| 2 |
|
| 3 |
# API URL - Backend API endpoint
|
| 4 |
+
# Choose ONE based on where your backend is deployed:
|
| 5 |
+
|
| 6 |
+
# Option 1: Local development (backend on localhost:3001)
|
| 7 |
NEXT_PUBLIC_API_URL=http://localhost:3001/api
|
| 8 |
+
|
| 9 |
+
# Option 2: Hugging Face Spaces backend (deployed)
|
| 10 |
+
# NEXT_PUBLIC_API_URL=https://saadrizvi09-wagerkit.hf.space/api
|
| 11 |
+
|
| 12 |
+
# Option 3: Docker/Production (both frontend + backend in same container)
|
| 13 |
+
# NEXT_PUBLIC_API_URL=/api
|
| 14 |
+
|
| 15 |
+
# Option 4: Custom domain
|
| 16 |
+
# NEXT_PUBLIC_API_URL=https://your-domain.com/api
|
frontend/.env.production.hf
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Production Environment - Connected to Hugging Face Spaces Backend
|
| 2 |
+
# Copy this file to .env.local to use HF Space backend
|
| 3 |
+
|
| 4 |
+
NEXT_PUBLIC_API_URL=https://saadrizvi09-wagerkit.hf.space/api
|