跳到主要内容

Self-Hosting Guide

This guide covers deploying TinyEmulator on your own server.

Prerequisites

RequirementVersion
Node.js>= 18
Go>= 1.21
Docker>= 24.0
Docker Compose>= 2.20

Quick Start with Docker

1. Clone the Repository

git clone https://github.com/SowrdLonn/tinyemulator.git
cd tinyemulator

2. Build the Frontend

cd TinyEmulator
npm install
npm run build

3. Build the Backend

cd ../retro-server
go build -o retro-server

4. Docker Compose Deployment

# docker-compose.yml
version: '3'

services:
# Backend API
retro-server:
image: retro-server:latest
ports:
- "8082:8082"
volumes:
- ./config:/etc/retro
- ./data:/app/data
- ./storage:/storage
- ./cheats:/app/cheats

# Frontend (Nginx)
nginx:
image: nginx:alpine
ports:
- "80:80"
volumes:
- ./TinyEmulator/dist:/var/www/html/tinyemulator
- ./default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- retro-server

5. Nginx Configuration

server {
listen 80;
server_name your-domain.com;

# TinyEmulator frontend
location /tinyemulator {
alias /var/www/html/tinyemulator/;
try_files $uri $uri/ /index.html;
}

# API proxy
location /api/ {
proxy_pass http://retro-server:8082;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}

# WebSocket tunnel
location /tunnel {
proxy_pass http://retro-server:8082;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}

6. Backend Configuration

# config/retro.yaml
server:
port: 8082

database:
driver: sqlite
dsn: /app/data/retro.db

jwt:
secret: your-secret-key
expire: 86400

cheats:
enabled: true
database_path: /app/cheats

cloudsave:
enabled: true
max_slots: 10

WebRTC Configuration

For netplay, configure STUN/TURN servers:

# retro.yaml
webrtc:
ice_servers:
- urls: "stun:stun.relay.metered.ca:80"
- urls: "turn:global.relay.metered.ca:80"
username: "your_username"
credential: "your_credential"

Environment Variables

VariableDefaultDescription
PORT8082Backend server port
DB_DRIVERsqliteDatabase driver
DB_DSN/app/data/retro.dbDatabase connection string
JWT_SECRET-JWT signing secret
CHEATS_ENABLEDfalseEnable cheats service
CHEATS_PATH/app/cheatsCheats database path