Skip to content

CachorroninjaBot/Vip-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌐 Languages

VIP API ⭐

A modern serverless API for managing VIP subscriptions with automatic webhook notifications. Built to run on Vercel with MongoDB as the database.

πŸš€ Features

  • βœ… Create, query, and delete VIP subscriptions
  • ⏰ Automatic processing of expired VIPs
  • πŸ”” Webhook notifications (optional)
  • πŸ“Š API health endpoint
  • πŸ”’ Flexible CORS configuration
  • πŸ“„ Pagination for VIP listings

πŸ“‹ Prerequisites

  • Node.js 18+
  • Vercel account
  • MongoDB database (we recommend MongoDB Atlas)

πŸ› οΈ Quick Setup

1. Clone and Configure

git clone <https://github.com/CachorroninjaBot/Vip-api>
cd vipapi-vercel
npm install
cp .env.example .env

2. Configure Environment Variables

Edit the .env file:

# Required
MONGODB_URI=mongodb+srv://username:[email protected]/database

# Optional (for webhooks)
WEBHOOK_URL=https://your-webhook-url.com/endpoint
WEBHOOK_AUTH=your-auth-token

# Production (optional)
ALLOWED_ORIGINS=https://yourdomain.com,https://app.yourdomain.com

3. Deploy to Vercel

# Via CLI
npm i -g vercel
vercel
vercel env add MONGODB_URI

# Or via web interface at vercel.com

πŸ“ API Endpoints

πŸ” Health Check

GET /api/health

Checks API status and database connection.

βž• Create VIP

POST /api/vip
Content-Type: application/json

{
  "userId": "user123",
  "timestamp": 1672531200,
  "plano": "Premium"
}

πŸ‘€ Get VIP

GET /api/vip/user123

πŸ“ List VIPs

GET /api/vips?page=1&limit=10

πŸ—‘οΈ Delete VIP

DELETE /api/vip/user123

⏰ Check Expired

POST /api/check-expired

πŸ”§ API Responses

Success - Create VIP (201)

{
  "message": "VIP purchase recorded successfully",
  "vip": {
    "userId": "user123",
    "timestamp": 1672531200,
    "plano": "Premium",
    "expiresAt": "2023-01-01T00:00:00.000Z"
  }
}

Get VIP (200)

{
  "userId": "user123",
  "timestamp": 1672531200,
  "plano": "Premium",
  "expiresAt": "2023-01-01T00:00:00.000Z",
  "isActive": true
}

Error - VIP Not Found (404)

{
  "error": "VIP subscription not found for this user"
}

βš™οΈ Expired VIP Automation

Since Vercel doesn't support native cron jobs (except on Pro plan), you can automate expired VIP checks using:

GitHub Actions

name: Check Expired VIPs
on:
  schedule:
    - cron: '*/30 * * * *'  # Every 30 minutes

jobs:
  check-expired:
    runs-on: ubuntu-latest
    steps:
      - name: Check Expired VIPs
        run: |
          curl -X POST https://your-api.vercel.app/api/check-expired

External Services

Vercel Cron (Pro Plan)

{
  "crons": [{
    "path": "/api/check-expired",
    "schedule": "*/30 * * * *"
  }]
}

🎯 Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Client App    │───▢│  Vercel API  │───▢│  MongoDB    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β–Ό
                       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                       β”‚   Webhook    β”‚
                       β”‚(Notifications)β”‚
                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ” Security

  • βœ… Strict input data validation
  • βœ… Parameter sanitization
  • βœ… Flexible CORS configuration
  • βœ… Webhook request timeouts
  • βœ… Detailed logs for auditing

πŸ“Š Monitoring

Real-time Logs

vercel logs --follow

Dashboard Metrics

Access Vercel dashboard β†’ Functions β†’ Logs

🚧 Limitations

Aspect Hobby Plan Pro Plan
Timeout 10 seconds 60 seconds
Cron Jobs ❌ βœ…
Cold Start ~1-3 seconds ~1-3 seconds

🀝 Contributing

  1. Fork the project
  2. Create your feature branch (git checkout -b feature/awesome-feature)
  3. Commit your changes (git commit -am 'Add: awesome feature')
  4. Push to the branch (git push origin feature/awesome-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License. See the LICENSE file for details.

πŸ†˜ Support

Found a bug? Open an issue or check the Vercel documentation.


Made with ❀️ for the community

About

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published