An open API service indexing awesome lists of open source software.

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.

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.



Create Heroku

2. Now deploy:



Deploy Heroku

#### DEPLOY TO VERCEL

1. If you don’t have an account on Vercel, create one.



Create Vercel

2. Now deploy:



Deploy Vercel

#### DEPLOY TO RAILWAY

1. If you don’t have an account on Railway, create one.



Create Railway

2. Now deploy:



Deploy Railway

#### DEPLOY TO RENDER

1. If you don’t have an account on Render, create one.



Create Render

2. Now deploy:



Deploy Render

#### DEPLOY TO KOYEB

1. If you don’t have an account on Koyeb, create one.



Create Koyeb

2. Now deploy:



Deploy Koyeb

#### DEPLOY TO REPLIT

1. If you don’t have an account on Replit, create one.



Create Replit

2. Now deploy:



Deploy Replit

## 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}}\$