portfolio-api / README.md
Pranabesh Singh
Add Hugging Face metadata header
07330df
|
Raw History Blame Contribute Delete
3.42 kB
metadata
title: Portfolio API
emoji: 🌌
colorFrom: yellow
colorTo: gray
sdk: docker
app_port: 7860
pinned: false

Pranabesh Portfolio API Server

This server stores highscores and current activity (mood) for the portfolio site. It supports both a local JSON file fallback for offline/development environments and MongoDB Atlas for full persistence in production on platforms like Vercel, Netlify, Render, or Railway.

πŸš€ Setup & Running Locally

  1. Install Dependencies

    cd server
    pnpm install
    
  2. Configure Environment Variables Create a .env file in the server directory (it is ignored by Git):

    PORT=3001
    ADMIN_PASSWORD=your_secure_passcode
    
    # Optional: Connect to MongoDB Atlas
    # MONGODB_URI=mongodb+srv://<user>:<password>@cluster0.xxxx.mongodb.net/
    # DB_NAME=pranabesh_portfolio
    
  3. Start the Server

    • Development (hot reloading):
      pnpm run dev
      
    • Production:
      pnpm start
      

If MONGODB_URI is omitted, the server will write data to a local file database at server/data/db.json.


🐳 Docker Deployment

You can build and run this server in a Docker container using the provided server/Dockerfile. By default, the server writes highscores and current activity to data/db.json inside the container.

Ephemeral Storage: If you run the container without a persistent volume and do not provide a MONGODB_URI environment variable, the database resets to defaults whenever the container restarts. This is ideal if you want a clean-slate reset on deployments.

1. Build the Docker Image

From the server directory:

docker build -t portfolio-api-server .

2. Run the Container

Run the container on port 3001 (set ADMIN_PASSWORD to your desired passcode):

docker run -d \
  -p 3001:3001 \
  -e ADMIN_PASSWORD="your_secure_passcode" \
  --name portfolio-api \
  portfolio-api-server

If you do want to plug in MongoDB Atlas to prevent resets:

docker run -d \
  -p 3001:3001 \
  -e ADMIN_PASSWORD="your_secure_passcode" \
  -e MONGODB_URI="mongodb+srv://..." \
  --name portfolio-api \
  portfolio-api-server

πŸ›  Deployment Guides

Render / Railway (Recommended for Standalone Backend)

Both Render and Railway are perfect for hosting node web services and support Docker out-of-the-box.

  1. Create a new Web Service pointing to your repository.
  2. Set the root directory of the project to server.
  3. Set the builder type to Docker (Railway/Render will automatically find and build Dockerfile inside the server/ directory).
  4. Add the following environment variables:
    • ADMIN_PASSWORD: A custom secret passcode you'll enter on your website to update your mood.
    • (Optional) MONGODB_URI: Your MongoDB Atlas connection string.
  5. Deploy the service. Copy the URL (e.g. https://portfolio-api.onrender.com).
  6. Set NEXT_PUBLIC_API_URL=https://portfolio-api.onrender.com in your Cloudflare Pages environment variables.

Vercel / Netlify Serverless Functions

You can also run these endpoints as Serverless functions. Under Vercel, a api/ directory in a server project will automatically route requests.

  • Ensure the cors headers match your frontend's domain name.
  • Connect to MongoDB Atlas since serverless platforms have completely ephemeral disks.