Spaces:
Running
Download README.md from pranz29/portfolio-api: direct link, hf CLI and curl.
- Browser
- Download file 3.42 kB
-
https://huggingface.co/spaces/pranz29/portfolio-api/resolve/main/README.md
- Command line
-
hf download hf://spaces/pranz29/portfolio-api/README.md
-
curl -L -o README.md https://huggingface.co/spaces/pranz29/portfolio-api/resolve/main/README.md
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
Install Dependencies
cd server pnpm installConfigure Environment Variables Create a
.envfile in theserverdirectory (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_portfolioStart the Server
- Development (hot reloading):
pnpm run dev - Production:
pnpm start
- Development (hot reloading):
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_URIenvironment 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.
- Create a new Web Service pointing to your repository.
- Set the root directory of the project to
server. - Set the builder type to Docker (Railway/Render will automatically find and build
Dockerfileinside theserver/directory). - 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.
- Deploy the service. Copy the URL (e.g.
https://portfolio-api.onrender.com). - Set
NEXT_PUBLIC_API_URL=https://portfolio-api.onrender.comin 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.