diff --git a/CHANGELOG.md b/CHANGELOG.md
index 37bf835dc..20a832cd5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -68,7 +68,7 @@ const firebaseConfig = {
```javascript
// firebase.js - NO CREDENTIALS
async function initializeFirebase() {
- const response = await fetch('/api/firebase-config');
+ const response = await fetch(`${APP_CONFIG.API_BASE_URL}/api/firebase-config`);
firebaseConfig = await response.json();
// Credentials loaded securely from server
}
diff --git a/Community/static/chat.js b/Community/static/chat.js
index 28c769297..a32246c7a 100644
--- a/Community/static/chat.js
+++ b/Community/static/chat.js
@@ -4,7 +4,7 @@ let username = "";
let currentCommunity = "";
function fetchCommunities() {
- fetch("/communities")
+ fetch(`${APP_CONFIG.API_BASE_URL}/api/communities`)
.then(res => res.json())
.then(communities => {
const list = document.getElementById('communitiesList');
@@ -21,7 +21,7 @@ function fetchCommunities() {
function addCommunity() {
const room = document.getElementById('newCommunityName').value.trim();
if (!room) return;
- fetch("/add_community", {
+ fetch(`${APP_CONFIG.API_BASE_URL}/add_community`, {
method: "POST",
headers: { 'Content-Type': "application/json" },
body: JSON.stringify({ room })
@@ -35,7 +35,7 @@ function addCommunity() {
function deleteCommunity() {
if (!currentCommunity) return;
- fetch("/delete_community", {
+ fetch(`${APP_CONFIG.API_BASE_URL}/delete_community`, {
method: "POST",
headers: { 'Content-Type': "application/json" },
body: JSON.stringify({ room: currentCommunity })
diff --git a/Community/templates/index.html b/Community/templates/index.html
index 49d17801f..7119f6304 100644
--- a/Community/templates/index.html
+++ b/Community/templates/index.html
@@ -98,7 +98,7 @@
Active Farmers:
}
function fetchCommunities() {
- fetch("/communities")
+ fetch(`${APP_CONFIG.API_BASE_URL}/api/communities`)
.then(res => res.json())
.then(communities => {
const list = document.getElementById('communitiesList');
@@ -115,7 +115,7 @@ Active Farmers:
function addCommunity() {
const room = document.getElementById('newCommunityName').value.trim();
if (!room) return;
- fetch("/add_community", {
+ fetch(`${APP_CONFIG.API_BASE_URL}/add_community`, {
method: "POST",
headers: { 'Content-Type': "application/json" },
body: JSON.stringify({ room })
@@ -129,7 +129,7 @@ Active Farmers:
function deleteCommunity() {
if (!currentCommunity) return;
- fetch("/delete_community", {
+ fetch(`${APP_CONFIG.API_BASE_URL}/delete_community`, {
method: "POST",
headers: { 'Content-Type': "application/json" },
body: JSON.stringify({ room: currentCommunity })
diff --git a/Crop Yield Prediction/crop_yield_app/static/script.js b/Crop Yield Prediction/crop_yield_app/static/script.js
index 66de1e0e8..f083e640e 100644
--- a/Crop Yield Prediction/crop_yield_app/static/script.js
+++ b/Crop Yield Prediction/crop_yield_app/static/script.js
@@ -124,7 +124,7 @@ document
}
// Make API request
- const response = await fetch("/predict", {
+ const response = await fetch(`${APP_CONFIG.API_BASE_URL}/predict`, {
method: "POST",
body: formData,
headers: headers,
diff --git a/Crop_Prices_Tracker/templates/crop_price_tracker.html b/Crop_Prices_Tracker/templates/crop_price_tracker.html
index a6b9c67cd..5d9248cef 100644
--- a/Crop_Prices_Tracker/templates/crop_price_tracker.html
+++ b/Crop_Prices_Tracker/templates/crop_price_tracker.html
@@ -93,7 +93,7 @@ 📈 Latest Market Prices
stateSelect.disabled = true;
stateSelect.classList.add("loading");
- fetch("/get_states?crop=" + this.value)
+ fetch(`${APP_CONFIG.API_BASE_URL}/get_states?crop=${this.value}`)
.then((res) => res.json())
.then((states) => {
stateSelect.innerHTML =
@@ -128,7 +128,7 @@ 📈 Latest Market Prices
marketSelect.disabled = true;
marketSelect.classList.add("loading");
- fetch(`/get_markets?crop=${crop}&state=${state}`)
+ fetch(`${APP_CONFIG.API_BASE_URL}/get_markets?crop=${crop}&state=${state}`)
.then((res) => res.json())
.then((markets) => {
marketSelect.innerHTML =
diff --git a/Forum/forum.js b/Forum/forum.js
index 3f420694c..89026a743 100644
--- a/Forum/forum.js
+++ b/Forum/forum.js
@@ -8,7 +8,7 @@ document.getElementById('forumForm').addEventListener('submit', function (e) {
};
- fetch('http://localhost:5000/forum', {
+ fetch(`${APP_CONFIG.API_BASE_URL}/forum`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
@@ -24,7 +24,7 @@ document.getElementById('forumForm').addEventListener('submit', function (e) {
function loadPosts() {
- fetch('http://localhost:5000/forum')
+ fetch(`${APP_CONFIG.API_BASE_URL}/api/forum_posts`)
.then(res => res.json())
.then(posts => {
const container = document.getElementById('forumPosts');
diff --git a/Labour_Alerts/static/script.js b/Labour_Alerts/static/script.js
index 902a56b83..eb73f2fc0 100644
--- a/Labour_Alerts/static/script.js
+++ b/Labour_Alerts/static/script.js
@@ -116,7 +116,7 @@ document.addEventListener('DOMContentLoaded', () => {
});
function fetchNewsUpdates() {
- fetch('http://127.0.0.1:5000/news')
+ fetch(`${APP_CONFIG.API_BASE_URL}/news`)
.then(response => response.json())
.then(data => {
if (data && Array.isArray(data.results)) {
diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md
index 54753d508..d351b1242 100644
--- a/PULL_REQUEST_TEMPLATE.md
+++ b/PULL_REQUEST_TEMPLATE.md
@@ -58,7 +58,7 @@ const firebaseConfig = {
```javascript
// firebase.js - NO CREDENTIALS
async function initializeFirebase() {
- const response = await fetch('/api/firebase-config');
+ const response = await fetch(`{APP_CONFIG.API_BASE_URL}/api/firebase-config`);
firebaseConfig = await response.json();
// Credentials loaded securely from server
}
diff --git a/app.py b/app.py
index 147a75c7d..54551dd20 100644
--- a/app.py
+++ b/app.py
@@ -1,5 +1,6 @@
from flask import Flask, request, jsonify, send_from_directory
-from google import genai
+from config.config import Config
+import google.generativeai as genai
import traceback
import os
import re
@@ -10,6 +11,7 @@
load_dotenv()
app = Flask(__name__, static_folder='.', static_url_path='')
+app.config["SECRET_KEY"] = Config.SECRET_KEY
CORS(app, resources={r"/*": {"origins": "http://127.0.0.1:5500"}})
# Input validation and sanitization functions
@@ -45,35 +47,33 @@ def validate_input(data):
return True, "Valid input"
# Initialize Gemini API
-API_KEY = os.environ.get('GEMINI_API_KEY')
-MODEL_ID = 'gemini-2.5-flash'
+API_KEY = os.environ.get("GEMINI_API_KEY")
+MODEL_ID = "gemini-2.5-flash"
-if not API_KEY:
- raise RuntimeError("GEMINI_API_KEY is not set in environment variables")
+client = None
-# Configure Gemini Client
-client = genai.Client(api_key=API_KEY)
+if API_KEY:
+ try:
+ client = genai.Client(api_key=API_KEY)
+ print("Gemini client initialized successfully.")
+ except Exception as e:
+ print("Failed to initialize Gemini client:", e)
+else:
+ print("Warning: GEMINI_API_KEY not set. AI features are disabled.")
"""Secure endpoint to provide Firebase configuration to client"""
@app.route('/api/firebase-config')
def get_firebase_config():
- try:
- return jsonify({
- 'apikey': os.environ['FIREBASE_API_KEY'],
- 'authDomain': os.environ['FIREBASE_AUTH_DOMAIN'],
- 'projectId': os.environ['FIREBASE_PROJECT_ID'],
- 'storageBucket': os.environ['FIREBASE_STORAGE_BUCKET'],
- 'messagingSenderId': os.environ['FIREBASE_MESSAGING_SENDER_ID'],
- 'appId': os.environ['FIREBASE_APP_ID'],
- 'measurementId': os.environ['FIREBASE_MEASUREMENT_ID']
-
- })
- except KeyError as e:
- return jsonify({
- "status": "error",
- "message":f"Missing environment variable: {str(e)}"
- }),500
+ return jsonify({
+ "apiKey": os.getenv("FIREBASE_API_KEY"),
+ "authDomain": os.getenv("FIREBASE_AUTH_DOMAIN"),
+ "projectId": os.getenv("FIREBASE_PROJECT_ID"),
+ "storageBucket": os.getenv("FIREBASE_STORAGE_BUCKET"),
+ "messagingSenderId": os.getenv("FIREBASE_MESSAGING_SENDER_ID"),
+ "appId": os.getenv("FIREBASE_APP_ID"),
+ "measurementId": os.getenv("FIREBASE_MEASUREMENT_ID")
+ })
@app.route('/process-loan', methods=['POST'])
diff --git a/chat.js b/chat.js
index efda20a51..3c6f35f54 100644
--- a/chat.js
+++ b/chat.js
@@ -107,7 +107,7 @@ document.addEventListener('DOMContentLoaded', () => {
}
// Call backend /api/chat
- const res = await fetch("/api/chat", {
+ const res = await fetch(`${APP_CONFIG.API_BASE_URL}/api/chat`, {
method: "POST",
headers: {
"Content-Type": "application/json"
diff --git a/config/config.py b/config/config.py
new file mode 100644
index 000000000..002c7ed25
--- /dev/null
+++ b/config/config.py
@@ -0,0 +1,10 @@
+import os
+
+class Config:
+ ENV = os.getenv("ENV", "development")
+
+ API_URL = os.getenv("API_URL", "http://localhost:5000")
+
+ SECRET_KEY = os.getenv("SECRET_KEY", "dev-secret")
+
+ MODEL_PATH = os.getenv("MODEL_PATH", "models/crop_model.pkl")
\ No newline at end of file
diff --git a/finance.js b/finance.js
index 354cc5712..274d7a9da 100644
--- a/finance.js
+++ b/finance.js
@@ -211,7 +211,7 @@ document.addEventListener('DOMContentLoaded', () => {
const typing = showTyping();
try {
- const res = await fetch(API_URL, {
+ const res = await fetch(`${APP_CONFIG.API_BASE_URL}/chat`, {
method: 'POST',
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
diff --git a/firebase.js b/firebase.js
index de6cfc34b..aac81e258 100644
--- a/firebase.js
+++ b/firebase.js
@@ -9,7 +9,7 @@ let auth = null;
// Initialize Firebase securely
async function initializeFirebase() {
try {
- const response = await fetch('/api/firebase-config');
+ const response = await fetch(`${APP_CONFIG.API_BASE_URL}/api/firebase-config`);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
diff --git a/index.html b/index.html
index 3e59bbfcb..59689e3eb 100644
--- a/index.html
+++ b/index.html
@@ -1615,7 +1615,6 @@ Contact
-