Skip to content

Make CORS and API URL configurable; add deployment guide - #3

Merged
TAPANANSHUTRIPATHY merged 8 commits into
mainfrom
backend
Jun 10, 2026
Merged

Make CORS and API URL configurable; add deployment guide#3
TAPANANSHUTRIPATHY merged 8 commits into
mainfrom
backend

Conversation

@TAPANANSHUTRIPATHY

Copy link
Copy Markdown
Owner

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:

  • Added a detailed DEPLOYMENT_GUIDE.md to document the deployment process for both frontend (Vercel) and backend (Render), including Firebase and secrets management.
  • Provided an example environment variable file (backend/.env.example) with clear instructions and descriptions for all required secrets and API keys.
  • Introduced a .dockerignore file to prevent sensitive files, Python caches, and development artifacts from being included in Docker images.
  • Updated .gitignore to match the .dockerignore and ensure sensitive and unnecessary files are not tracked by git.
  • Modified the backend Dockerfile to dynamically use the PORT environment variable (as required by Render), defaulting to 8000 for local development.

Backend Code Improvements:

  • Enhanced Firebase service account credential handling in DB_operations.py:
    • Automatically detects the Firebase JSON file in the backend directory or uses the GOOGLE_APPLICATION_CREDENTIALS environment variable.
    • Provides clear error messages if credentials are missing.
  • Improved user update logic to support fallback search by Aadhaar number if a user ID is not found, increasing robustness.
  • Hardened OTP validation by ensuring both stored and entered OTPs are compared as strings, preventing type mismatch errors.
  • Cleaned up and simplified docstrings and removed inline testing code from DB_operations.py for production readiness. [1] [2] [3] [4] [5] [6] [7] [8]
  • Added missing import for timedelta in LLM_inference.py.

These changes collectively improve deployment clarity, backend reliability, and the security of sensitive information.

References:

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.
Copilot AI review requested due to automatic review settings June 10, 2026 00:36
@vercel

vercel Bot commented Jun 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
shramikare-final Ready Ready Preview, Comment Jun 10, 2026 12:36am

@TAPANANSHUTRIPATHY
TAPANANSHUTRIPATHY merged commit 0848e99 into main Jun 10, 2026
2 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 via LanguageContext.
  • 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.example files, 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 (see main.py), but .env.example doesn'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 thread DEPLOYMENT_GUIDE.md
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 thread backend/.env.example
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 thread backend/main.py
Comment on lines +26 to 30
origins = os.getenv("ALLOWED_ORIGINS", "*").split(",")
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_origins=origins,
allow_credentials=True,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants