tragarz-server
v1.1.0
Published
Server component for Tragarz - lightweight Git alternative for solo developers
Downloads
8
Maintainers
Readme
Tragarz Server
HTTP server component for Tragarz file synchronization system.
Installation
npm install -g tragarz-serverQuick Start
1. Initialize Server
# Create a directory for your server
mkdir ~/my-tragarz-server
cd ~/my-tragarz-server
# Initialize server (creates config and projects directory)
tragarz-server initThis creates:
tragarzserver.json- Server configurationprojects/- Directory for project files
2. Configure (Optional)
Edit tragarzserver.json:
{
"port": 8080,
"password": "admin123",
"dataDir": "./projects",
"maxProjectSize": "1GB",
"allowedHosts": ["*"]
}3. Start Server
tragarz-server startThe server will:
- Load configuration from current directory
- Create projects directory if needed
- Start listening on configured port
Commands
tragarz-server init
Initialize server in current directory. Creates:
- Configuration file (
tragarzserver.json) - Projects directory
tragarz-server start
Start the server using configuration from current directory.
tragarz-server help
Show help message with all available commands.
Configuration
tragarzserver.json
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| port | number | 8080 | Server port |
| password | string | "admin123" | Authentication password |
| dataDir | string | "./projects" | Projects storage directory |
| maxProjectSize | string | "1GB" | Maximum project size |
| allowedHosts | array | ["*"] | CORS allowed hosts |
Security
- Change the default password immediately
- Use HTTPS in production (reverse proxy recommended)
- Limit
allowedHoststo specific domains if needed - Keep
maxProjectSizereasonable to prevent abuse
API Endpoints
Authentication
POST /auth- Authenticate and get token
Projects
GET /projects- List all projectsPOST /projects/:name- Create new projectGET /projects/:name/info- Get project info
Files
GET /projects/:name/files- List project filesPOST /projects/:name/files- Upload filesGET /projects/:name/files/*- Download fileDELETE /projects/:name/files/*- Delete file
Snapshots
POST /projects/:name/snapshot- Create snapshotGET /projects/:name/snapshots- List snapshotsPOST /projects/:name/restore/:snapshotId- Restore snapshot
Development
Local Development
cd server
npm install
npm link
# In your test directory
mkdir ~/test-tragarz
cd ~/test-tragarz
tragarz-server init
tragarz-server startProject Structure
server/
├── src/
│ ├── server.js # Main server class
│ ├── auth.js # Authentication manager
│ ├── projectManager.js # Project operations
│ ├── fileManager.js # File operations
│ └── snapshotManager.js # Snapshot operations
├── bin/
│ └── tragarz-server.js # CLI wrapper
└── package.jsonSecurity Features
- Password-based authentication
- Token-based session management (JWT)
- Rate limiting (100 requests per 15 minutes)
- Path traversal protection
- File size limits
- Input validation
- CORS configuration
- Helmet security headers
Deployment
Simple Deployment
# On your server
npm install -g tragarz-server
cd /var/tragarz
tragarz-server init
# Edit config
nano tragarzserver.json
# Start (consider using pm2 or systemd)
tragarz-server startWith PM2
npm install -g pm2
cd /var/tragarz
tragarz-server init
# Create ecosystem file
pm2 start "tragarz-server start" --name tragarz
pm2 save
pm2 startupWith systemd
Create /etc/systemd/system/tragarz.service:
[Unit]
Description=Tragarz Server
After=network.target
[Service]
Type=simple
User=tragarz
WorkingDirectory=/var/tragarz
ExecStart=/usr/bin/tragarz-server start
Restart=on-failure
[Install]
WantedBy=multi-user.targetThen:
sudo systemctl enable tragarz
sudo systemctl start tragarzBehind Nginx
server {
listen 80;
server_name tragarz.example.com;
location / {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}Troubleshooting
Port Already in Use
# Change port in config
nano tragarzserver.json
# Set "port": 8081Permission Issues
# Make sure projects directory is writable
chmod 755 projects/Can't Find Configuration
Server looks for tragarzserver.json in the current working directory.
Make sure you:
- Run
tragarz-server initin your desired directory - Run
tragarz-server startfrom the same directory
# Wrong
cd ~
tragarz-server init
cd /tmp
tragarz-server start # Will fail - no config here!
# Correct
cd ~/my-tragarz
tragarz-server init
tragarz-server start # Works - config is hereLicense
MIT
