A deployable markdown editor that connects with your self hosted files and lets you edit in a beautiful interface
at main 538 lines 11 kB view raw view rendered
1# MarkEdit Setup Guide 2 3This guide will help you set up and deploy MarkEdit for production or development use. 4 5## Table of Contents 6 7- [Prerequisites](#prerequisites) 8- [GitHub OAuth Setup](#github-oauth-setup) 9- [Development Setup](#development-setup) 10- [Docker Deployment](#docker-deployment) 11- [Production Deployment](#production-deployment) 12- [Configuration Reference](#configuration-reference) 13- [Troubleshooting](#troubleshooting) 14 15## Prerequisites 16 17### For Docker Deployment 18- Docker 20.x or higher 19- Docker Compose 2.x or higher 20- GitHub account with OAuth app 21 22### For Local Development 23- Go 1.24 or higher 24- Bun 1.x or higher (for frontend) 25- Git 26- GitHub account with OAuth app 27 28## GitHub OAuth Setup 29 30MarkEdit uses GitHub OAuth for authentication. You need to create a GitHub OAuth application: 31 32### 1. Create OAuth Application 33 341. Go to [GitHub Developer Settings](https://github.com/settings/developers) 352. Click **"New OAuth App"** 363. Fill in the application details: 37 - **Application name**: `MarkEdit` (or your preferred name) 38 - **Homepage URL**: `http://localhost:3000` (for development) 39 - **Authorization callback URL**: `http://localhost:8080/auth/github/callback` 404. Click **"Register application"** 41 42### 2. Get Credentials 43 44After registration, you'll see: 45- **Client ID** - Copy this value 46- **Client Secret** - Click "Generate a new client secret" and copy the value 47 48> ⚠️ **Important**: Keep your Client Secret secure! Never commit it to version control. 49 50### 3. Production URLs 51 52For production deployment, create a separate OAuth app with production URLs: 53- **Homepage URL**: `https://yourdomain.com` 54- **Authorization callback URL**: `https://yourdomain.com/auth/github/callback` 55 56## Development Setup 57 58### 1. Clone Repository 59 60```bash 61git clone https://tangled.org/usaa.ma/markedit 62cd markedit 63``` 64 65### 2. Configure Environment Variables 66 67#### Backend Configuration 68 69Create `backend/.env`: 70 71```bash 72cd backend 73cp .env.example .env 74``` 75 76Edit `backend/.env`: 77 78```bash 79# GitHub OAuth 80GITHUB_CLIENT_ID=your_github_oauth_client_id_here 81GITHUB_CLIENT_SECRET=your_github_oauth_client_secret_here 82 83# Session Security 84SESSION_SECRET=generate-a-random-32-character-string-here 85 86# Database 87DATABASE_PATH=./data/markedit.db 88 89# Git Cache 90GIT_CACHE_DIR=./data/repos 91 92# CORS (adjust based on your frontend URL) 93CORS_ALLOWED_ORIGINS=http://localhost:4321,http://localhost:3000 94 95# Server 96PORT=8080 97``` 98 99**Generate SESSION_SECRET**: 100```bash 101# On macOS/Linux: 102openssl rand -base64 32 103 104# Or use Go: 105go run -c 'package main; import ("crypto/rand"; "encoding/base64"; "fmt"); func main() { b := make([]byte, 32); rand.Read(b); fmt.Println(base64.StdEncoding.EncodeToString(b)) }' 106``` 107 108#### Frontend Configuration 109 110Create `frontend/.env`: 111 112```bash 113cd ../frontend 114echo "PUBLIC_API_URL=http://localhost:8080" > .env 115``` 116 117### 3. Run Backend 118 119```bash 120cd backend 121 122# Install dependencies 123go mod download 124 125# Create data directory 126mkdir -p data 127 128# Run server 129go run cmd/server/main.go 130``` 131 132Backend will start on `http://localhost:8080` 133 134### 4. Run Frontend 135 136In a new terminal: 137 138```bash 139cd frontend 140 141# Install dependencies 142bun install 143 144# Start dev server 145bun run dev 146``` 147 148Frontend will start on `http://localhost:4321` 149 150### 5. Access Application 151 1521. Open browser to `http://localhost:4321` 1532. Click "Sign in with GitHub" 1543. Authorize the application 1554. Start editing! 156 157## Docker Deployment 158 159Docker deployment is the recommended method for production. 160 161### 1. Configure Environment 162 163Create `.env` in the project root: 164 165```bash 166cp .env.example .env 167``` 168 169Edit `.env`: 170 171```bash 172# GitHub OAuth (use production OAuth app) 173GITHUB_CLIENT_ID=your_production_github_oauth_client_id 174GITHUB_CLIENT_SECRET=your_production_github_oauth_client_secret 175 176# Session Security 177SESSION_SECRET=generate-a-secure-random-32-character-string 178 179# Database 180DATABASE_PATH=/app/data/markedit.db 181 182# Git Cache 183GIT_CACHE_DIR=/app/data/repos 184 185# CORS (adjust for your domain) 186CORS_ALLOWED_ORIGINS=https://yourdomain.com,http://localhost:3000 187 188# Server 189PORT=8080 190``` 191 192### 2. Build Images 193 194```bash 195make build 196``` 197 198Or manually: 199 200```bash 201docker-compose build 202``` 203 204### 3. Start Services 205 206```bash 207make up 208``` 209 210Or manually: 211 212```bash 213docker-compose up -d 214``` 215 216### 4. Verify Deployment 217 218Check if services are running: 219 220```bash 221make logs 222``` 223 224Or: 225 226```bash 227docker-compose logs -f 228``` 229 230Access the application at `http://localhost:3000` 231 232### 5. Stop Services 233 234```bash 235make down 236``` 237 238## Production Deployment 239 240### Option 1: Docker on VPS 241 242#### 1. Server Setup 243 244On your VPS (Ubuntu/Debian): 245 246```bash 247# Update system 248sudo apt update && sudo apt upgrade -y 249 250# Install Docker 251curl -fsSL https://get.docker.com -o get-docker.sh 252sudo sh get-docker.sh 253 254# Install Docker Compose 255sudo apt install docker-compose-plugin 256 257# Create app directory 258mkdir -p ~/markedit 259cd ~/markedit 260``` 261 262#### 2. Deploy Application 263 264```bash 265# Clone repository 266git clone https://tangled.org/usaa.ma/markedit 267 268# Configure environment 269cp .env.example .env 270nano .env # Edit with production values 271 272# Build and start 273docker-compose up -d 274 275# Check logs 276docker-compose logs -f 277``` 278 279#### 3. Setup Reverse Proxy (nginx) 280 281Install nginx: 282 283```bash 284sudo apt install nginx certbot python3-certbot-nginx 285``` 286 287Create nginx config `/etc/nginx/sites-available/markedit`: 288 289```nginx 290server { 291 listen 80; 292 server_name yourdomain.com; 293 294 location / { 295 proxy_pass http://localhost:3000; 296 proxy_http_version 1.1; 297 proxy_set_header Upgrade $http_upgrade; 298 proxy_set_header Connection 'upgrade'; 299 proxy_set_header Host $host; 300 proxy_cache_bypass $http_upgrade; 301 proxy_set_header X-Real-IP $remote_addr; 302 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 303 proxy_set_header X-Forwarded-Proto $scheme; 304 } 305} 306``` 307 308Enable site and get SSL: 309 310```bash 311sudo ln -s /etc/nginx/sites-available/markedit /etc/nginx/sites-enabled/ 312sudo nginx -t 313sudo systemctl reload nginx 314sudo certbot --nginx -d yourdomain.com 315``` 316 317### Option 2: Docker on Cloud Platform 318 319#### AWS ECS / Google Cloud Run / Azure Container Instances 320 3211. Build and push images to container registry: 322 323```bash 324# Tag images 325docker tag markedit-backend:latest your-registry/markedit-backend:latest 326docker tag markedit-frontend:latest your-registry/markedit-frontend:latest 327 328# Push images 329docker push your-registry/markedit-backend:latest 330docker push your-registry/markedit-frontend:latest 331``` 332 3332. Deploy using platform-specific tools 3343. Configure environment variables in platform dashboard 3354. Set up load balancer and SSL certificate 336 337### Option 3: Manual Deployment 338 339#### Backend 340 341```bash 342# Build binary 343cd backend 344go build -o markedit-server cmd/server/main.go 345 346# Run with systemd 347sudo cp markedit-server /usr/local/bin/ 348sudo nano /etc/systemd/system/markedit.service 349``` 350 351Create systemd service: 352 353```ini 354[Unit] 355Description=MarkEdit Server 356After=network.target 357 358[Service] 359Type=simple 360User=www-data 361WorkingDirectory=/var/www/markedit 362EnvironmentFile=/var/www/markedit/.env 363ExecStart=/usr/local/bin/markedit-server 364Restart=always 365 366[Install] 367WantedBy=multi-user.target 368``` 369 370Enable and start: 371 372```bash 373sudo systemctl enable markedit 374sudo systemctl start markedit 375``` 376 377#### Frontend 378 379```bash 380cd frontend 381bun install 382bun run build 383 384# Serve with nginx 385sudo cp -r dist/* /var/www/html/ 386``` 387 388## Configuration Reference 389 390### Backend Environment Variables 391 392| Variable | Required | Default | Description | 393|----------|----------|---------|-------------| 394| `GITHUB_CLIENT_ID` | Yes | - | GitHub OAuth client ID | 395| `GITHUB_CLIENT_SECRET` | Yes | - | GitHub OAuth client secret | 396| `SESSION_SECRET` | Yes | - | 32+ character random string for session encryption | 397| `DATABASE_PATH` | No | `./data/markedit.db` | Path to SQLite database file | 398| `GIT_CACHE_DIR` | No | `./data/repos` | Directory for git repository cache | 399| `CORS_ALLOWED_ORIGINS` | No | `http://localhost:4321` | Comma-separated allowed origins | 400| `PORT` | No | `8080` | Server port | 401 402### Frontend Environment Variables 403 404| Variable | Required | Default | Description | 405|----------|----------|---------|-------------| 406| `PUBLIC_API_URL` | Yes | - | Backend API URL (e.g., `http://localhost:8080`) | 407 408### Docker Compose Ports 409 410| Service | Internal Port | External Port | Description | 411|---------|---------------|---------------|-------------| 412| Backend | 8080 | 8080 | API server | 413| Frontend | 80 | 3000 | Web interface | 414 415## Troubleshooting 416 417### GitHub OAuth Issues 418 419**Problem**: "OAuth callback error" or "Invalid client" 420 421**Solution**: 4221. Verify `GITHUB_CLIENT_ID` and `GITHUB_CLIENT_SECRET` are correct 4232. Check callback URL in GitHub OAuth app matches your backend URL 4243. Ensure callback URL format: `http://localhost:8080/auth/github/callback` 425 426### Database Issues 427 428**Problem**: "Unable to open database" 429 430**Solution**: 4311. Ensure data directory exists: `mkdir -p data` 4322. Check file permissions: `chmod 755 data` 4333. Verify `DATABASE_PATH` environment variable 434 435### Git Operations Fail 436 437**Problem**: "Failed to clone repository" or "Authentication failed" 438 439**Solution**: 4401. User must have granted repository access during OAuth 4412. Check GitHub token has correct scopes (repo) 4423. Verify `GIT_CACHE_DIR` is writable 443 444### CORS Issues 445 446**Problem**: "CORS policy: No 'Access-Control-Allow-Origin' header" 447 448**Solution**: 4491. Add frontend URL to `CORS_ALLOWED_ORIGINS` 4502. Format: `http://localhost:4321,https://yourdomain.com` 4513. Restart backend server 452 453### Docker Build Fails 454 455**Problem**: Build errors or dependency issues 456 457**Solution**: 458```bash 459# Clean Docker cache 460docker-compose down -v 461docker system prune -a 462 463# Rebuild from scratch 464make build 465make up 466``` 467 468### Frontend Can't Connect to Backend 469 470**Problem**: "Network error" or "Failed to fetch" 471 472**Solution**: 4731. Verify backend is running: `curl http://localhost:8080/health` 4742. Check `PUBLIC_API_URL` in frontend `.env` 4753. Ensure CORS is configured correctly 4764. Check browser console for specific errors 477 478### Port Already in Use 479 480**Problem**: "Address already in use" 481 482**Solution**: 483```bash 484# Find process using port 485lsof -i :8080 # or :3000 486 487# Kill process 488kill -9 <PID> 489 490# Or change port in configuration 491``` 492 493## Security Best Practices 494 4951. **Never commit secrets**: Keep `.env` files out of version control 4962. **Use strong SESSION_SECRET**: Minimum 32 random characters 4973. **Enable HTTPS**: Use SSL certificates in production 4984. **Restrict CORS**: Only allow trusted domains 4995. **Regular updates**: Keep dependencies up to date 5006. **Backup database**: Regularly backup `markedit.db` 5017. **Monitor logs**: Check for unauthorized access attempts 502 503## Backup and Restore 504 505### Backup 506 507```bash 508# Database 509cp data/markedit.db backups/markedit-$(date +%Y%m%d).db 510 511# Git cache (optional) 512tar -czf backups/repos-$(date +%Y%m%d).tar.gz data/repos/ 513``` 514 515### Restore 516 517```bash 518# Database 519cp backups/markedit-20240101.db data/markedit.db 520 521# Restart services 522docker-compose restart 523``` 524 525## Support 526 527- **Documentation**: [README.md](./README.md) 528- **Issues**: [Tangled Issues](https://tangled.org/usaa.ma/markedit/issues) 529 530## Next Steps 531 532After setup: 5331. Sign in with GitHub 5342. Configure your first repository 5353. Start editing markdown files 5364. Create your first pull request 537 538Happy editing! 🎉