Self Hosting
NxGate GitHub repository adalah monorepo yang berisi kode frontend dan backend. Frontend dibangun dengan SvelteKit dan backend adalah NodeJS Express server.
Prerequisites
VPS
VPS dengan NodeJS >= 16.x terinstall
MySQL Database
MySQL 8.0+ atau MariaDB 10.5+
SMTP Server
Untuk mengirim email verifikasi dan reset password
Domain
2 subdomain: satu untuk frontend, satu untuk API
Architecture
NxGate terdiri dari dua bagian:
Frontend
Web interface yang digunakan user. Ini adalah static site yang bisa di-host di static file server manapun (Nginx, Cloudflare Pages, Vercel, dll).
Backend
Server yang berkomunikasi dengan frontend dan melakukan verifikasi lisensi. Ini adalah NodeJS Express server yang bisa di-host di mana saja yang support NodeJS.
Frontend dan backend harus di-serve di domain atau subdomain yang berbeda. Contoh: frontend di nxgate.example.com dan backend di api.nxgate.example.com.
Setup dengan Docker (Recommended)
NxGate dapat di-host menggunakan Docker. Repository GitHub berisi file yang diperlukan termasuk automatic SSL certificate melalui Let's Encrypt dan reverse-proxy melalui Caddy.
docker-compose.yml
1version: '3.8'23services:4 nxgate-backend:5 image: noxlydev/nxgate-backend:latest6 ports:7 - "3000:3000"8 environment:9 - NODE_ENV=production10 - DATABASE_URL=mysql://user:password@db:3306/nxgate11 - JWT_SECRET=your-secret-key12 - SMTP_HOST=smtp.example.com13 - SMTP_PORT=58714 - SMTP_USERNAME=user15 - SMTP_PASSWORD=password16 depends_on:17 - db18 restart: unless-stopped1920 nxgate-frontend:21 image: noxlydev/nxgate-frontend:latest22 ports:23 - "8080:80"24 environment:25 - PUBLIC_BACKEND_URL=https://api.nxgate.example.com26 restart: unless-stopped2728 db:29 image: mysql:8.030 environment:31 - MYSQL_ROOT_PASSWORD=rootpassword32 - MYSQL_DATABASE=nxgate33 - MYSQL_USER=user34 - MYSQL_PASSWORD=password35 volumes:36 - nxgate-data:/var/lib/mysql37 restart: unless-stopped3839 caddy:40 image: caddy:241 ports:42 - "80:80"43 - "443:443"44 volumes:45 - ./Caddyfile:/etc/caddy/Caddyfile46 - caddy-data:/data47 restart: unless-stopped4849volumes:50 nxgate-data:51 caddy-data:
Caddyfile
1nxgate.example.com {2 reverse_proxy nxgate-frontend:803}45api.nxgate.example.com {6 reverse_proxy nxgate-backend:30007}
Manual Setup: Frontend
- 1
Clone repository:
git clone https://github.com/NoxlyDev/NxGate - 2
Navigate ke frontend:
cd frontend - 3
Setup environment variables di .env
- 4
Build:
npm install && npm run build - 5
Output build ada di
frontend/build
Frontend Environment Variables
1PUBLIC_BACKEND_URL=https://api.nxgate.example.com2PUBLIC_RECAPTCHA_SITE_KEY=your-recaptcha-site-key3PUBLIC_GOOGLE_AUTH_CLIENT_ID=none
Nginx Configuration
1server {2 listen 80;3 server_name nxgate.example.com;45 root /var/www/nxgate;6 index index.html;78 location / {9 try_files $uri $uri/ /index.html =404;10 }11}
Manual Setup: Backend
- 1
Navigate ke backend:
cd backend - 2
Setup environment variables di .env
- 3
Install dan setup database:
npm install && npm run prisma-up && npm run prisma-gen - 4
Start server:
npm run start
Backend Environment Variables
1NODE_ENV=production2HEX_USER_ID_OFFSET=03PORT=30004DATABASE_URL="mysql://user:password@localhost:3306/nxgate"5SMTP_HOST=smtp.example.com6SMTP_USERNAME=user7SMTP_PASSWORD=password8SMTP_PORT=5879SMTP_SENDER="NxGate <noreply@example.com>"10JWT_SECRET=your-random-secret-key-here11RECAPTCHA_SECRET_KEY=your-recaptcha-secret12SIGN_IN_URL=https://nxgate.example.com/auth/login13RESET_PASSWORD_URL=https://nxgate.example.com/auth/password14CORS_ORIGIN=https://nxgate.example.com15GOOGLE_AUTH_CLIENT_ID=none
Menggunakan dengan Wrapper Libraries
Library wrapper NxGate secara default menggunakan public NxGate server di api.nxgate.noxly.dev. Untuk menggunakan self-hosted server, Anda perlu mengkonfigurasi server URL.
1// Konfigurasi wrapper untuk self-hosted server2NxGateConfig config = new NxGateConfig()3 .setUserId("YOUR_USER_ID")4 .setLicenseKey(licenseKey)5 .setServerUrl("https://api.nxgate.example.com"); // Custom server URL67NxGateClient client = new NxGateClient(config);