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

docker-compose.yml
1version: '3.8'
2
3services:
4 nxgate-backend:
5 image: noxlydev/nxgate-backend:latest
6 ports:
7 - "3000:3000"
8 environment:
9 - NODE_ENV=production
10 - DATABASE_URL=mysql://user:password@db:3306/nxgate
11 - JWT_SECRET=your-secret-key
12 - SMTP_HOST=smtp.example.com
13 - SMTP_PORT=587
14 - SMTP_USERNAME=user
15 - SMTP_PASSWORD=password
16 depends_on:
17 - db
18 restart: unless-stopped
19
20 nxgate-frontend:
21 image: noxlydev/nxgate-frontend:latest
22 ports:
23 - "8080:80"
24 environment:
25 - PUBLIC_BACKEND_URL=https://api.nxgate.example.com
26 restart: unless-stopped
27
28 db:
29 image: mysql:8.0
30 environment:
31 - MYSQL_ROOT_PASSWORD=rootpassword
32 - MYSQL_DATABASE=nxgate
33 - MYSQL_USER=user
34 - MYSQL_PASSWORD=password
35 volumes:
36 - nxgate-data:/var/lib/mysql
37 restart: unless-stopped
38
39 caddy:
40 image: caddy:2
41 ports:
42 - "80:80"
43 - "443:443"
44 volumes:
45 - ./Caddyfile:/etc/caddy/Caddyfile
46 - caddy-data:/data
47 restart: unless-stopped
48
49volumes:
50 nxgate-data:
51 caddy-data:

Caddyfile

Caddyfile
1nxgate.example.com {
2 reverse_proxy nxgate-frontend:80
3}
4
5api.nxgate.example.com {
6 reverse_proxy nxgate-backend:3000
7}

Manual Setup: Frontend

  1. 1

    Clone repository:

    git clone https://github.com/NoxlyDev/NxGate
  2. 2

    Navigate ke frontend:

    cd frontend
  3. 3

    Setup environment variables di .env

  4. 4

    Build:

    npm install && npm run build
  5. 5

    Output build ada di frontend/build

Frontend Environment Variables

.env
1PUBLIC_BACKEND_URL=https://api.nxgate.example.com
2PUBLIC_RECAPTCHA_SITE_KEY=your-recaptcha-site-key
3PUBLIC_GOOGLE_AUTH_CLIENT_ID=none

Nginx Configuration

/etc/nginx/sites-available/nxgate
1server {
2 listen 80;
3 server_name nxgate.example.com;
4
5 root /var/www/nxgate;
6 index index.html;
7
8 location / {
9 try_files $uri $uri/ /index.html =404;
10 }
11}

Manual Setup: Backend

  1. 1

    Navigate ke backend:

    cd backend
  2. 2

    Setup environment variables di .env

  3. 3

    Install dan setup database:

    npm install && npm run prisma-up && npm run prisma-gen
  4. 4

    Start server:

    npm run start

Backend Environment Variables

.env
1NODE_ENV=production
2HEX_USER_ID_OFFSET=0
3PORT=3000
4DATABASE_URL="mysql://user:password@localhost:3306/nxgate"
5SMTP_HOST=smtp.example.com
6SMTP_USERNAME=user
7SMTP_PASSWORD=password
8SMTP_PORT=587
9SMTP_SENDER="NxGate <noreply@example.com>"
10JWT_SECRET=your-random-secret-key-here
11RECAPTCHA_SECRET_KEY=your-recaptcha-secret
12SIGN_IN_URL=https://nxgate.example.com/auth/login
13RESET_PASSWORD_URL=https://nxgate.example.com/auth/password
14CORS_ORIGIN=https://nxgate.example.com
15GOOGLE_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.

Custom Server URL
1// Konfigurasi wrapper untuk self-hosted server
2NxGateConfig config = new NxGateConfig()
3 .setUserId("YOUR_USER_ID")
4 .setLicenseKey(licenseKey)
5 .setServerUrl("https://api.nxgate.example.com"); // Custom server URL
6
7NxGateClient client = new NxGateClient(config);

Dokumentasi Terkait