Simple PeerJS server setup with Docker Compose, allowing you to easily run a WebRTC signaling server locally or in the cloud.
- Docker and Docker Compose installed
- Port 9000 free (or change in
.envfile)
cp .env.example .env
# Edit the .env file as neededchmod +x start.sh
./start.sh| Parameter | Default | Description | Example Value |
|---|---|---|---|
PORT |
9000 | Docker exposed port | 9008 |
PEERJS_PATH |
/peerjs | Base path for PeerJS server | '/myapp' |
ALIVE_TIMEOUT |
60000 | Keep-alive timeout (ms) | 120000 |
EXPIRE_TIMEOUT |
5000 | Time (ms) until peer ID deletion | 10000 |
CONCURRENT_LIMIT |
5000 | Max concurrent connections | 10000 |
ALLOW_DISCOVERY |
true | Allow /peers endpoint | 'false' |
CORS_ORIGINS |
* | CORS allowed origins | 'https://example.com, https://another.com' |
KEY |
peerjs | Default API key | 'myapp' |
USE_CREDENTIALS |
false | Use credentials for connections | 'true' |
VERIFY_WS_ORIGIN |
true | Verify WebSocket origin header | 'false' |
PROXIED |
false | Enable if behind a proxy | 'true' |
LOG_LEVEL |
INFO | Logging level (DEBUG, INFO, WARN, ERROR) | DEBUG |
ENABLE_RATE_LIMIT |
false | Enable rate limiting | 'true' |
MAX_CONNECTIONS_PER_IP |
50 | Max connections per IP (0 = unlimited) | 10 |
CONNECTION_TIMEOUT_MS |
300000 | Connection timeout in ms. Closes websocket if no activity in this time. | 60000 |
You can deploy the PeerJS server to various cloud platforms. Below are example configuration files for some popular services:
- Railway: See railway.toml for configuration.
- Fly.io: See fly.toml for configuration.
- Render: See render.yaml for configuration.
- Sign up or log in to Railway.
- Create a new project and link your GitHub repository.
- Deploying will start automatically.
- Set the environment variables from the
.envfile in the Railway project settings. Most importantly, check the:CORS_ORIGINSvariable to allow your frontend application to connect to localhost during development and production (depending on your domain e.g.http://localhost:3000,https://yourdomain.com).USE_CREDENTIALSvariable totrueif you want to use credentials for connections.ENABLE_RATE_LIMITvariable totrueto enable rate limiting.MAX_CONNECTIONS_PER_IPvariable to set the maximum connections per IP.CONNECTION_TIMEOUT_MSvariable to set the connection timeout in milliseconds.PROXIEDvariable totrueif you are deploying behind a proxy.PORTthere are limitations on Railway for custom ports, so it's best to use ports between 0 and 65535
- Sign up or log in to Fly.io.
- Deploy your GIT repository
- Sign up or log in to Render.
- Add a new Web Service and connect your GitHub repository.
- Set the environment variables from the
.envfile in the Render service settings. Most importantly, check the:CORS_ORIGINSvariable to allow your frontend application to connect to localhost during development and production (depending on your domain e.g.http://localhost:3000,https://yourdomain.com).USE_CREDENTIALSvariable totrueif you want to use credentials for connections.ENABLE_RATE_LIMITvariable totrueto enable rate limiting.MAX_CONNECTIONS_PER_IPvariable to set the maximum connections per IP.CONNECTION_TIMEOUT_MSvariable to set the connection timeout in milliseconds.
MIT