Skip to content
This repository was archived by the owner on Jul 21, 2025. It is now read-only.

rohanrgit/rWeb

Repository files navigation

rWeb Backend Server

A Node.js/Express backend server for Rohan's website that provides API endpoints for various integrations.

Features

  • 🚀 Express Server: Simple and fast web server
  • 🔐 Environment Variables: Secure API key management with .env file
  • 🌐 CORS Configuration: Properly configured for local development
  • 🤖 Gemini API Integration: Proxy endpoint for AI-powered features
  • 📊 Health Check: Server status monitoring

Setup

Prerequisites

  • Node.js 18+
  • npm or yarn

Installation

  1. Install dependencies:
npm install
  1. Set up environment variables:
cp .env .env.local
  1. Edit .env.local and add your API keys:
GEMINI_API_KEY=your_actual_gemini_api_key_here

Development

Start the development server:

npm run dev

Or start in production mode:

npm start

The server will run on http://localhost:3000

API Endpoints

Health Check

  • GET /health
  • Returns server status and timestamp

Gemini AI Integration

  • POST /api/gemini
  • Body: { "prompt": "Your prompt here" }
  • Returns AI-generated response

Posts (Example)

  • GET /api/posts
  • Returns blog posts data

Frontend Integration

The frontend (index.html) has been updated to use the backend API instead of making direct API calls. This provides:

  • Security: API keys are stored server-side
  • CORS Handling: Proper cross-origin request handling
  • Error Handling: Centralized error management
  • Rate Limiting: Can be easily added to the backend

File Structure

.
├── server.js          # Main Express server
├── package.json       # Project dependencies
├── .env              # Environment variables template
├── .env.local        # Your actual environment variables (create this)
├── main.js           # Frontend JavaScript
├── index.html        # Main HTML file
└── README.md         # This file

Environment Variables

Variable Description Required
PORT Server port (default: 3000) No
NODE_ENV Environment mode No
GEMINI_API_KEY Google Gemini API key Yes
CORS_ORIGIN Allowed CORS origins No

CORS Configuration

The server is configured to allow requests from:

  • http://localhost:3000
  • http://127.0.0.1:5500
  • http://localhost:5500

You can modify these in the .env file or add more origins as needed.

Usage

  1. Start the backend server: npm run dev
  2. Open index.html in your browser or serve it with a local server
  3. The frontend will automatically connect to the backend API

Security Notes

  • Keep your .env.local file secure and never commit it to version control
  • The .env file is a template - replace placeholder values with real API keys
  • API keys are handled server-side for security

Development vs Production

In development mode (NODE_ENV=development), the server provides detailed error messages. In production, error details are hidden for security.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published