server command runs Surge as a background daemon without the TUI, exposing an HTTP API for remote control.
Usage
Description
Starts Surge in headless server mode. The command:- Runs without a Terminal User Interface
- Exposes HTTP API on specified port (default: 1700+)
- Logs download events to stdout
- Supports browser extension integration
- Can be controlled via CLI commands (
surge add,surge ls, etc.) - Runs until manually stopped or all downloads complete (with
--exit-when-done)
Server mode is ideal for running Surge on headless systems, remote servers, or as a background service.
Arguments
One or more URLs to download on startup. URLs can include mirrors using comma separation.Example:
Flags
Path to a file containing URLs to download (one per line).Short form:
-bExample:Port to listen on for HTTP API. If 0, automatically finds an available port starting from 1700.Short form:
-pExample:Default output directory for downloads. If not specified, uses configured default directory.Short form:
-oExample:Exit automatically when all downloads complete. Useful for batch processing.Example:
Do not automatically resume paused downloads from previous sessions on startup.Example:
Set custom authentication token for API clients. If not provided, generates and persists a random UUID.Can also be set via
SURGE_TOKEN environment variable.Example:Subcommands
start
Alias forsurge server:
surge server.
stop
Stop a running Surge server:status
Check if Surge server is running:Examples
Basic Server Start
Start with Downloads
Batch Processing
Custom Port and Output
With Custom Token
Check Status
Stop Server
Server Output
Event Logging
The server logs download events to stdout:Startup Messages
API Server
Endpoints
The server exposes these HTTP endpoints:POST /download- Add new downloadGET /download?id=<id>- Get download statusGET /downloads- List all downloadsPOST /pause?id=<id>- Pause downloadPOST /resume?id=<id>- Resume downloadPOST /delete?id=<id>- Remove downloadPUT /update-url?id=<id>- Update download URLGET /health- Health check (no auth required)GET /events- Server-Sent Events stream
Authentication
All endpoints (except/health) require Bearer token authentication:
CORS
The server enables CORS for browser extension integration:Access-Control-Allow-Origin: *- Supports private network access
- Handles preflight OPTIONS requests
Controlling the Server
Add Downloads
List Downloads
Pause/Resume
Remove Downloads
Connect TUI
Connect a TUI to the running server:Process Management
PID File
Server writes its PID to:Port File
Server writes its port to:Lock File
Prevents multiple instances from running simultaneously.Daemon Mode
Using nohup
Using systemd
Create/etc/systemd/system/surge.service:
Using Docker
Exit Behavior
Normal Exit
Press Ctrl+C or send SIGTERM:Exit When Done
With--exit-when-done, server exits when all downloads complete:
Cleanup
On exit, the server:- Pauses active downloads
- Closes all connections
- Removes PID and port files
- Releases lock file
Remote Access
Bind Address
Server binds to0.0.0.0 by default, accepting connections from any interface.
Firewall
Open the port in your firewall:Security
Recommended setup:- Run server on localhost only
- Use nginx/caddy as reverse proxy with HTTPS
- Use strong authentication token
- Restrict access by IP if possible
Troubleshooting
Port Already in Use
Already Running
Related Commands
- surge - Run with TUI
- surge connect - Connect TUI to server
- surge add - Add downloads to server
- surge token - Get authentication token