A lightweight and serverless CDN utilizing MEGA for file storage and delivery.
- Stores in mega.nz cloud
- Multi-account load balancing
- PostgreSQL, MongoDB, SQLite support
- Auto-delete & auth token
- Rate limit & size check
- Shortened filenames
git clone https://github.com/IRON-M4N/MegaCDN.git
cd MegaCDN
npm install
cp .env.example .env
npm run build
npm start| Method | Endpoint | Description |
|---|---|---|
POST |
/upload |
Upload files |
GET |
/file/:name |
Serve file by custom CDN URL |
GET |
/media/:name |
Original MEGA URL |
GET |
/info |
Server info |
GET |
/health |
Health check |
Example:
curl -X POST -F "[email protected]" http://cdn.yourdomain.com/upload# Single mode (default)
curl -X POST -F "[email protected]" http://cdn.yourdomain.com/upload
# Dual mode (specify MEGA email)
curl -X POST -F "[email protected]" -F "mode=dual" -F "[email protected]" http://cdn.yourdomain.com/upload
# With Auth
curl -H "Authorization: Bearer YOUR_TOKEN" ...{
"success": true,
"files": [
{
"url": "https://cdn.yourdomaincom/media/abcDEF123.png",
"name": "skirk.png",
"size": 1523200,
"formattedSize": "1.45 MB",
"mime": "image/png",
"expires": "1800s",
"formattedExpires": "30 minutes"
}
]
}
- Optional Bearer token auth
- Rate limit per window
- File size/type validation
- Auto-delete with TTL
- Fork this repo
- Create a branch
feature-xyz - Commit & push
- Open a pull request