Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions Community/static/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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 })
Expand All @@ -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 })
Expand Down
6 changes: 3 additions & 3 deletions Community/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ <h4>Active Farmers:</h4>
}

function fetchCommunities() {
fetch("/communities")
fetch(`${APP_CONFIG.API_BASE_URL}/api/communities`)
.then(res => res.json())
.then(communities => {
const list = document.getElementById('communitiesList');
Expand All @@ -115,7 +115,7 @@ <h4>Active Farmers:</h4>
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 })
Expand All @@ -129,7 +129,7 @@ <h4>Active Farmers:</h4>

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 })
Expand Down
2 changes: 1 addition & 1 deletion Crop Yield Prediction/crop_yield_app/static/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions Crop_Prices_Tracker/templates/crop_price_tracker.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ <h3>📈 Latest Market Prices</h3>
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 =
Expand Down Expand Up @@ -128,7 +128,7 @@ <h3>📈 Latest Market Prices</h3>
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 =
Expand Down
4 changes: 2 additions & 2 deletions Forum/forum.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion Labour_Alerts/static/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
46 changes: 23 additions & 23 deletions app.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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'])
Expand Down
2 changes: 1 addition & 1 deletion chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 10 additions & 0 deletions config/config.py
Original file line number Diff line number Diff line change
@@ -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")
2 changes: 1 addition & 1 deletion finance.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
Expand Down
8 changes: 7 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1615,7 +1615,6 @@ <h4>Contact</h4>

<script type="module" src="index.js"></script>

<script src="index.js"></script>

<script>
// Theme Toggle
Expand Down Expand Up @@ -1697,6 +1696,7 @@ <h4>Contact</h4>
const hamburgerBtn = document.getElementById('hamburgerBtn');
const mobileMenu = document.getElementById('mobileMenu');
const mobileMenuOverlay = document.getElementById('mobileMenuOverlay');
const mobileCloseBtn = document.querySelector('.mobile-close-btn');

function closeMobileMenu() {
mobileMenu.classList.remove('active');
Expand All @@ -1719,11 +1719,17 @@ <h4>Contact</h4>
});

// ❌ CLOSE — TOUCH SAFE



if(mobileCloseBtn){

mobileCloseBtn.addEventListener('pointerdown', (e) => {
e.preventDefault();
e.stopPropagation();
closeMobileMenu();
});
}

// BACKUP FOR OLD MOBILE BROWSERS
mobileCloseBtn.addEventListener('touchstart', (e) => {
Expand Down
25 changes: 24 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,27 @@ localStorage.setItem(
JSON.stringify(tasks)
);

renderRoadmap(tasks);
renderRoadmap(tasks);

async function initializeFirebase() {
try {
const response = await fetch('/api/firebase-config');
const config = await response.json();

if (!config.apiKey) {
console.warn("Firebase not configured on server.");
return;
}

console.log("Firebase config loaded:", config);

// If you later add Firebase SDK, initialize here
// initializeApp(config);

} catch (error) {
console.error("Failed to load Firebase config:", error);
}
}

// Call it
initializeFirebase();
3 changes: 3 additions & 0 deletions js/js/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
window.APP_CONFIG = {
API_BASE_URL: "http://127.0.0.1:5000"
};
2 changes: 1 addition & 1 deletion json-chatbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class JSONChatbot {
*/
async loadResponses() {
try {
const response = await fetch('./chatbot-responses.json');
const response = await fetch(`${APP_CONFIG.API_BASE_URL}/api/chatbot-responses.json`);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
Expand Down