Make CORS and API URL configurable; add deployment guide - #3
Merged
Conversation
Read allowed CORS origins from ALLOWED_ORIGINS (comma-separated) in backend and use that for CORSMiddleware instead of a hardcoded "*". Add a frontend .env.example with VITE_API_URL and update frontend config to use import.meta.env.VITE_API_URL with a localhost fallback. This enables configuring API base URL and allowed origins for different environments (local, production).
Add a comprehensive DEPLOYMENT_GUIDE.md explaining frontend (Vercel) and backend (Render) deployment, environment variable setup, Firebase credential handling (base64 or secret file), and external API configuration. Update backend/Dockerfile to use the PORT environment variable provided by Render and default to 8000 for local development; remove the previous EXPOSE and hardcoded 8080 CMD.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
This PR improves ShramiKare’s deployability and runtime configurability by centralizing the frontend API base URL, making backend CORS configurable, adding deployment documentation, and introducing new UI flows (QR scanning + outbreak dashboard) alongside backend support (local QR generation, OCR endpoint, Firebase credential auto-detection).
Changes:
- Added configurable frontend API base (
VITE_API_URL) and updated multiple pages to use it, plus introduced multi-language UI support viaLanguageContext. - Added new QR scanner and outbreak/outbreak-metrics dashboard pages with corresponding backend endpoints/utilities (including local QR generation with
qrcode). - Added deployment/ops artifacts: deployment guide,
.env.examplefiles, Docker ignore/gitignore updates, and Dockerfile PORT handling.
Reviewed changes
Copilot reviewed 27 out of 34 changed files in this pull request and generated 19 comments.
Show a summary per file
| File | Description |
|---|---|
| frontend/ShramiKare/src/pages/RegisterPage.jsx | Switch registration to JSON payload + adds Aadhaar OCR auto-fill modal and UI refactor. |
| frontend/ShramiKare/src/pages/QrScannerPage.jsx | New QR scanner page (webcam + image upload) to fetch user by Aadhaar. |
| frontend/ShramiKare/src/pages/OutbreakDashboardPage.jsx | New outbreak dashboard page consuming /outbreak-metrics/ and triggering reminder sends. |
| frontend/ShramiKare/src/pages/OtpLoginPage.jsx | Uses configurable API base and language translations for login/OTP flow. |
| frontend/ShramiKare/src/pages/LandingPage.jsx | Adds language-driven strings to landing content. |
| frontend/ShramiKare/src/pages/DoctorDetailsPage.jsx | Uses configurable API base and language translations for facility lookup. |
| frontend/ShramiKare/src/pages/DigitalHealthIdPage.jsx | Uses configurable API base, improves error handling, and adjusts QR generation call. |
| frontend/ShramiKare/src/pages/AadhaarCardPage.jsx | Uses configurable API base and improves empty/error states. |
| frontend/ShramiKare/src/main.jsx | Wraps app in LanguageProvider. |
| frontend/ShramiKare/src/Layout.jsx | Adds language selector + new nav links (scan + admin dashboard). |
| frontend/ShramiKare/src/context/LanguageContext.jsx | New translation/context implementation with localStorage persistence. |
| frontend/ShramiKare/src/config.js | Centralizes API base URL using import.meta.env.VITE_API_URL. |
| frontend/ShramiKare/src/App.jsx | Adds routes for scanner + admin dashboard; updates userId state init. |
| frontend/ShramiKare/package.json | Adds jsqr and react-markdown dependencies. |
| frontend/ShramiKare/package-lock.json | Locks new dependencies and transitive packages. |
| frontend/ShramiKare/index.html | Updates favicon/title/metadata for ShramiKare branding. |
| frontend/ShramiKare/.env.example | Documents VITE_API_URL for frontend deployments. |
| DEPLOYMENT_GUIDE.md | New deployment guide for Vercel + Render, Firebase secrets handling. |
| backend/seed_demo_data.py | Adds a Firestore demo data seeder for users/facilities. |
| backend/requirements.txt | Adds qrcode[pil] and normalizes python-multipart line. |
| backend/QR_generator.py | Replaces external QR API with local base64 QR generation. |
| backend/main.py | Adds configurable CORS origins, outbreak metrics endpoint, OCR endpoint, and other robustness changes. |
| backend/LLM_inference.py | Adds lazy Gemini init + fallback follow-up date prediction. |
| backend/Dockerfile | Uses dynamic ${PORT:-8000} for Render compatibility. |
| backend/DB_operations.py | Improves Firebase credential discovery + OTP hardening + cleanup. |
| backend/.gitignore | Ignores firebase-adminsdk JSONs and Python artifacts/uploads. |
| backend/.env.example | New backend env example documenting external service keys. |
| backend/.dockerignore | Prevents secrets and build artifacts from entering Docker images. |
Files not reviewed (1)
- frontend/ShramiKare/package-lock.json: Language not supported
Comments suppressed due to low confidence (1)
backend/.env.example:26
- Backend CORS is now configurable via
ALLOWED_ORIGINS(seemain.py), but.env.exampledoesn't document this variable, making it easy to misconfigure CORS in production.
# ── Firebase (optional — only needed if NOT using a JSON file in backend/) ─────
# If you have the firebase-adminsdk JSON file in backend/, this is not needed.
# GOOGLE_APPLICATION_CREDENTIALS=/path/to/your-firebase-adminsdk.json
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+1
to
+3
| import React, { useState, useRef, useEffect } from "react"; | ||
| import jsQR from "jsqr"; | ||
|
|
| aadhaarId = parts[parts.length - 1]; | ||
| } | ||
|
|
||
| const res = await fetch(`http://localhost:8000/api/users/by-aadhaar/${aadhaarId}`); |
Comment on lines
+1
to
+2
| import React, { useState, useEffect } from "react"; | ||
| import ReactMarkdown from "react-markdown"; |
Comment on lines
+17
to
+18
| const res = await fetch("http://localhost:8000/api/outbreak-metrics/"); | ||
| const json = await res.json(); |
Comment on lines
+31
to
+32
| const res = await fetch("http://localhost:8000/api/send-followup-reminders/"); | ||
| const result = await res.json(); |
Comment on lines
+66
to
+72
| 4. **Handling the Firebase Credentials File** | ||
| The backend requires the `shramikare-firebase-adminsdk-fbsvc-*.json` file. Since you should **not** commit this to GitHub, you need to securely inject it: | ||
| * **Option A (Base64 Env Variable):** Encode the JSON file contents to base64. Create an env variable `FIREBASE_CREDENTIALS_BASE64` in Render. In your `DB_operations.py` or `main.py`, decode this string and write it to a temporary file or load the dict directly using `credentials.Certificate(json.loads(decoded_string))`. | ||
| * **Option B (Secret File):** In the Render dashboard, under **Advanced**, use the **Secret Files** feature. | ||
| * **Filename:** `shramikare-firebase-adminsdk.json` | ||
| * **Contents:** Paste the entire contents of your Firebase JSON key. | ||
| * Update your code (`DB_operations.py`) to reference this file's path (Render places it in `/etc/secrets/shramikare-firebase-adminsdk.json`). |
Comment on lines
+19
to
+21
| # ── QR Code API ──────────────────────────────────────────────────────────────── | ||
| # Get from: https://www.qrcoder.co.uk/ | ||
| QRCODER_API_KEY=your_qrcoder_api_key_here |
Comment on lines
+68
to
+70
| setForm(prev => ({ ...prev, [name]: file })); | ||
| setPreviews(prev => ({ ...prev, [name]: URL.createObjectURL(file) })); | ||
| } |
Comment on lines
+119
to
+136
| // Build JSON payload (excluding file fields for now) | ||
| const payload = { | ||
| name: form.name, | ||
| age: parseInt(form.age), | ||
| blood_group: form.blood_group, | ||
| language: form.language, | ||
| gender: form.gender, | ||
| address: form.address, | ||
| aadhaarNumber: form.aadhaarNumber, | ||
| phonenumber: parseInt(form.phonenumber), | ||
| originState: form.originState, | ||
| originDistrict: form.originDistrict, | ||
| destinationDistrict: form.destinationDistrict, | ||
| records: form.records, | ||
| companies: form.companies, | ||
| profilePhotoUrl: "https://avatar.iran.liara.run/public/", | ||
| aadhaarPhotoUrl: "/sample_aadhar.png", | ||
| }; |
Comment on lines
+26
to
30
| origins = os.getenv("ALLOWED_ORIGINS", "*").split(",") | ||
| app.add_middleware( | ||
| CORSMiddleware, | ||
| allow_origins=["*"], | ||
| allow_origins=origins, | ||
| allow_credentials=True, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces several important improvements to the ShramiKare application's backend and deployment workflow. The main changes include the addition of a comprehensive deployment guide, enhancements to backend configuration and environment management, improved handling of Firebase credentials, and codebase cleanup for better maintainability and security.
Deployment and Environment Management:
DEPLOYMENT_GUIDE.mdto document the deployment process for both frontend (Vercel) and backend (Render), including Firebase and secrets management.backend/.env.example) with clear instructions and descriptions for all required secrets and API keys..dockerignorefile to prevent sensitive files, Python caches, and development artifacts from being included in Docker images..gitignoreto match the.dockerignoreand ensure sensitive and unnecessary files are not tracked by git.Dockerfileto dynamically use thePORTenvironment variable (as required by Render), defaulting to 8000 for local development.Backend Code Improvements:
DB_operations.py:GOOGLE_APPLICATION_CREDENTIALSenvironment variable.DB_operations.pyfor production readiness. [1] [2] [3] [4] [5] [6] [7] [8]timedeltainLLM_inference.py.These changes collectively improve deployment clarity, backend reliability, and the security of sensitive information.
References: