From 80de89e8465b9e56a34082af2bb9c29c147ae691 Mon Sep 17 00:00:00 2001 From: Mehal Srivastava Date: Thu, 23 Oct 2025 23:00:20 +0530 Subject: [PATCH] cleanup --- .env.example | 2 -- CONFIG.md | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 14 +++++++++++--- server/server.js | 5 ++++- 4 files changed, 64 insertions(+), 6 deletions(-) delete mode 100644 .env.example create mode 100644 CONFIG.md diff --git a/.env.example b/.env.example deleted file mode 100644 index 7f70772..0000000 --- a/.env.example +++ /dev/null @@ -1,2 +0,0 @@ -GOOGLE_MAPS_API_KEY=your_api_key_here -PORT=3000 diff --git a/CONFIG.md b/CONFIG.md new file mode 100644 index 0000000..0b21752 --- /dev/null +++ b/CONFIG.md @@ -0,0 +1,49 @@ +# SipMap Configuration Guide + +## πŸ”‘ API Key Management + +### Single Source of Truth +The application uses **ONE** configuration file for the Google Maps API key: + +``` +πŸ“ SipMap/ + └── .env ← YOUR API KEY GOES HERE (ONLY PLACE TO CHANGE IT) +``` + +### How to Update Your API Key + +1. **Open the file**: `/Users/mehalsrivastava/GitHub/SipMap/.env` +2. **Update the key**: Change `GOOGLE_MAPS_API_KEY=your_current_key` to your new key +3. **Restart the server**: The server will automatically pick up the new key + +### Example .env file: +```bash +GOOGLE_MAPS_API_KEY=AIzaSyAOFpadsj8FUVZatR4TpCtr2gTCcEdOTAY +PORT=3000 +NODE_ENV=production +``` + +## πŸ”„ Quick Restart Commands + +When you change the API key, restart the server: + +```bash +# Stop any running server +pkill -f "node server.js" + +# Start the server +cd /Users/mehalsrivastava/GitHub/SipMap/server && node server.js +``` + +## βœ… Verification + +After updating the API key: +1. Check server logs show: `API Key loaded successfully` +2. Test a search in your browser at `http://localhost:5500` +3. Verify API calls return restaurant/cafe data + +## 🚨 Important Notes + +**No more duplicate .env files** - Server reads from root `.env` only +- **One place to change API key** - Only edit `/SipMap/.env` +- **Version control** - The `.env` file is gitignored for security diff --git a/README.md b/README.md index 524dc63..0eaa9f6 100644 --- a/README.md +++ b/README.md @@ -41,10 +41,18 @@ Option B β€” Serve locally (recommended): python3 -m http.server (any portnum of your choice) ``` -## πŸ”§ Configuration (optional) -If you use a backend or API keys, copy `.env.example` to `.env` and fill in values. The front‑end reads from your environment only if you wire a server or bundler that injects them. +## πŸ”§ Configuration -- `.env.example` β€” reference for required variables +### πŸ”‘ API Key Setup (Simplified) + +**One place to manage your API key:** Edit the `.env` file in the root directory + +1. **Edit `.env`**: Replace `your_google_maps_api_key_here` with your actual API key +2. **Restart server**: If running the backend, restart to pick up changes + +See `CONFIG.md` for detailed instructions. + +### Google Cloud Setup - Set up your project in the Google Cloud Console. You'll enter a project name and billing information. Your website won't work as it should unless you enable billing, but you won't be charged if the API doesn't get called past the monthly limit (we'll teach you how to cap it at the limit, which is usually 10,000 API calls). diff --git a/server/server.js b/server/server.js index a7c8906..6d69110 100644 --- a/server/server.js +++ b/server/server.js @@ -1,7 +1,10 @@ const express = require('express'); const cors = require('cors'); const fetch = require('node-fetch'); -require('dotenv').config(); +const path = require('path'); + +// Configure dotenv to read from the root project directory +require('dotenv').config({ path: path.join(__dirname, '..', '.env') }); // Middleware to log request details const logRequestDetails = (req, res, next) => {