This is my silly JS (I'm gonna kms) project called StarAPI. It provides various endpoints for system information, health checks, and more. Also comes with a Discordbot :p
- Secure Authentication: JWT token-based authentication with encryption
- System Monitoring: Real-time metrics for CPU, memory, disk, and network
- Discord Bot Integration: Monitor your system through Discord commands
- Comprehensive Logging: System, error, and audit logging
- Role-based Access Control: Secure API endpoints with role permissions
- Node.js 18+
- PostgreSQL (or Heroku Postgres for cloud deployment)
- Basic Linux knowledge
- Git
-
Install Heroku CLI and login:
heroku login
-
Create a new Heroku app:
heroku create your-starapi-app
-
Add Heroku Postgres addon:
heroku addons:create heroku-postgresql:mini
-
Set environment variables:
heroku config:set NODE_ENV=production heroku config:set JWT_SECRET=$(openssl rand -hex 32) heroku config:set ENCRYPTION_KEY=$(openssl rand -hex 32) heroku config:set BOT_SECRET=$(openssl rand -hex 16) heroku config:set BOT_SECRETV2=$(openssl rand -hex 32) heroku config:set DISCORD_TOKEN=your_discord_bot_token heroku config:set CLIENT_ID=your_discord_client_id heroku config:set DISCORD_ADMIN_IDS=your_discord_user_id
-
Deploy the application:
git push heroku main
-
Scale the dynos:
heroku ps:scale web=1 worker=1
-
View logs:
heroku logs --tail
Required environment variables:
DATABASE_URL
(automatically set by Heroku Postgres)NODE_ENV=production
JWT_SECRET
(32-byte hex string)ENCRYPTION_KEY
(32-byte hex string)DISCORD_TOKEN
(Discord bot token)CLIENT_ID
(Discord application client ID)BOT_SECRET
(Bot authentication secret)BOT_SECRETV2
(Bot API token)
Optional:
DISCORD_ADMIN_IDS
(Comma-separated Discord user IDs)FRONTEND_URL
(Frontend application URL)ADMIN_PASSWORD
(Custom admin password, otherwise random)
-
Clone the repository:
git clone https://github.com/O4bit/StarAPI.git cd StarAPI
-
Install dependencies:
npm install
-
Set up the PostgreSQL database:
# Login as postgres user sudo su - postgres # Access PostgreSQL CLI psql
Then create the database and tables:
CREATE DATABASE starapi; \c starapi CREATE TABLE users ( id SERIAL PRIMARY KEY, username VARCHAR(255) UNIQUE NOT NULL, password_hash VARCHAR(255) NOT NULL, roles TEXT[] NOT NULL DEFAULT '{user}' ); CREATE TABLE user_tokens ( token_id UUID PRIMARY KEY, user_id INTEGER REFERENCES users(id), expires_at TIMESTAMP NOT NULL, revoked BOOLEAN DEFAULT FALSE, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); CREATE TABLE bot_tokens ( bot_id VARCHAR(50) PRIMARY KEY, token TEXT NOT NULL, expires_at TIMESTAMP NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP );
-
Create a
.env
file with your configuration:# Server Configuration PORT=3030 NODE_ENV=development # Database Configuration DATABASE_URL=postgresql://username:password@localhost:5432/starapi # Security JWT_SECRET=your_jwt_secret_key ENCRYPTION_KEY=32_byte_hex_encryption_key # Discord Bot DISCORD_TOKEN=your_discord_bot_token CLIENT_ID=your_discord_client_id DISCORD_ADMIN_IDS=discord_user_id1,discord_user_id2 VERIFIED_ROLE_ID=discord_role_id # Bot Authentication BOT_SECRET=your_bot_secret BOT_SECRETV2=your_bot_secret_v2
-
Start the server:
npm start
POST /api/auth/login
- Authenticate and get tokenPOST /api/auth/logout
- Invalidate current tokenGET /api/auth/me
- Get current user infoPOST /api/auth/users
- Create new user (admin only)POST /api/auth/bot-token
- Generate bot token
GET /api/system/health
- Basic health check and uptimeGET /api/system/metrics
- Detailed system metrics (CPU, memory, disk, network)GET /api/system/info
- System information (OS, CPU, hardware details)GET /api/system/network
- Network interfaces and statisticsPOST /api/system/commands
- Execute system commands (admin only)
GET /api/logs
- Retrieve system logs with filtering optionsGET /api/logs/audit
- Access audit logs (admin only)
/status
- Display current system status/metrics
- Show detailed system metrics/logs [severity] [hours]
- View recent logs (admin/verified only)/reboot
- Reboot the system (admin only)/system-info
- Show detailed system information/network-info
- Display network interface details
- Encrypted JWT tokens using AES-256-GCM
- Database token validation and revocation
- Role-based access control for API endpoints
- Comprehensive audit logging
- Rate limiting to prevent brute force attacks
Run in development mode with auto-restart:
npm run dev
Run the Discord bot separately:
npm run bot
- Check logs:
heroku logs --tail
- Restart app:
heroku restart
- Check dyno status:
heroku ps
- View config:
heroku config
- Reset database:
heroku pg:reset DATABASE_URL
- Run setup again:
heroku run npm run setup-heroku