https://github.com/iron-m4n/megacdn
A lightweight and serverless CDN utilizing MEGA for file storage and delivery.
https://github.com/iron-m4n/megacdn
api cdn fastify mega megajs
Last synced: 8 months ago
JSON representation
A lightweight and serverless CDN utilizing MEGA for file storage and delivery.
- Host: GitHub
- URL: https://github.com/iron-m4n/megacdn
- Owner: IRON-M4N
- Created: 2025-02-22T11:22:23.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-10-01T02:50:21.000Z (8 months ago)
- Last Synced: 2025-10-01T04:25:16.703Z (8 months ago)
- Topics: api, cdn, fastify, mega, megajs
- Language: TypeScript
- Homepage:
- Size: 229 KB
- Stars: 10
- Watchers: 1
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
$\textcolor{red}{Mega}\textcolor{white}{CDN}$
A lightweight and serverless CDN utilizing MEGA for file storage and delivery.
---
## Features
- Stores in mega.nz cloud
- Multi-account load balancing
- PostgreSQL, MongoDB, SQLite support
- Auto-delete & auth token
- Rate limit & size check
- Shortened filenames
---
#### DEPLOY TO HEROKU
1. If you don’t have an account on Heroku, create one.
#### DEPLOY TO VERCEL
1. If you don’t have an account on Vercel, create one.
#### DEPLOY TO RAILWAY
1. If you don’t have an account on Railway, create one.
#### DEPLOY TO RENDER
1. If you don’t have an account on Render, create one.
#### DEPLOY TO KOYEB
1. If you don’t have an account on Koyeb, create one.
#### DEPLOY TO REPLIT
1. If you don’t have an account on Replit, create one.
## Installation
```bash
git clone https://github.com/IRON-M4N/MegaCDN.git
cd MegaCDN
npm install
cp .env.example .env
npm run build
npm start
````
---
## API Endpoints
| 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:**
```bash
curl -X POST -F "file=@image.jpg" http://cdn.yourdomain.com/upload
```
---
## Upload Modes
```bash
# Single mode (default)
curl -X POST -F "file=@file.jpg" http://cdn.yourdomain.com/upload
# Dual mode (specify MEGA email)
curl -X POST -F "file=@file.jpg" -F "mode=dual" -F "email=user@mega.com" http://cdn.yourdomain.com/upload
# With Auth
curl -H "Authorization: Bearer YOUR_TOKEN" ...
```
---
## Example Response
```json
{
"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"
}
]
}
```
---
## Security
* Optional Bearer token auth
* Rate limit per window
* File size/type validation
* Auto-delete with TTL
---
## Contributing
1. Fork this repo
2. Create a branch `feature-xyz`
3. Commit & push
4. Open a pull request
---
\$\frac{\text{Made with } \heartsuit \text{ by IRON-M4N}}{\text{2025 - 6969}}\$