Backend server for rwrs-another-page.
This project serves as the backend for rwrs-another-page, developed using Rust and the Salvo framework. Its primary function is to proxy API requests for the Running with Rifles game server list, provide static file serving, and serve game map configuration data.
- Install Rust development environment
# Install rustup
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Or download the installer for Windows- Clone the repository
git clone https://github.com/zhaozisong0/rwrs-server.git
cd rwrs-server- Local development
# Run the development server
cargo runBy default, the server will start on 127.0.0.1:5800. You can modify this using environment variables:
# Custom IP and port
HOST=0.0.0.0 PORT=8080 cargo run
# Custom cache and rate limiting settings
CACHE_DURATION_SECS=60 RATE_LIMIT_SECS=10 cargo run| Variable | Default | Description |
|---|---|---|
HOST |
127.0.0.1 |
Server bind address |
PORT |
5800 |
Server port |
MAPS_CONFIG |
maps.json |
Maps configuration file path |
CACHE_DURATION_SECS |
3 |
Cache expiry time in seconds |
RATE_LIMIT_SECS |
3 |
Rate limit interval in seconds |
ANDROID_REPO_URL |
(empty) | GitHub repository URL for Android app releases |
WEB_REPO_URL |
(empty) | GitHub repository URL for Web app releases |
Health check endpoint that returns "pong".
Returns the latest release information for Android and Web applications configured through environment variables. The endpoint fetches the latest release information from GitHub repositories.
{
"android": {
"version": "v2.0.0",
"url": "https://github.com/owner/android-repo/releases/tag/v2.0.0"
},
"web": {
"version": "v1.5.0",
"url": "https://github.com/owner/web-repo/releases/tag/v1.5.0"
}
}If a repository URL is not configured or the repository has no releases, the corresponding fields will be null:
{
"android": {
"version": null,
"url": null
},
"web": {
"version": null,
"url": null
}
}# Set repository URLs when running the server
ANDROID_REPO_URL=https://github.com/your-org/android-app \
WEB_REPO_URL=https://github.com/your-org/web-app \
cargo run
# Or in Docker
docker run -e ANDROID_REPO_URL=https://github.com/your-org/android-app \
-e WEB_REPO_URL=https://github.com/your-org/web-app \
-p 8080:5800 \
rwrs-serverNote: Only GitHub repository URLs are supported. The API will return null for non-GitHub URLs.
Returns game map configuration data. See the Maps Configuration section below for details.
Proxies requests to the Running with Rifles game server list API. Supports query parameters for filtering.
Proxies requests to the Running with Rifles player statistics API. Returns HTML content with player rankings and statistics. Supports query parameters for filtering and sorting.
You can pass query parameters to filter and sort the player data:
sort: Field to sort by (e.g., kills, deaths, score)order: Sort order (asc, desc)- Other parameters supported by the original API
Example:
# Get players sorted by kills in descending order
curl "http://localhost:5800/api/player_list?sort=kills&order=desc"
# Get all players
curl http://localhost:5800/api/player_listMaps are configured through a JSON file specified by the MAPS_CONFIG environment variable (default: maps.json). The configuration is exposed via the /api/maps endpoint.
You can specify a custom location for the maps configuration file:
# Use a custom configuration file
MAPS_CONFIG=/etc/rwrs/custom-maps.json cargo run
# In Docker
docker run -e MAPS_CONFIG=/config/maps.json -v $(pwd)/maps.json:/config/maps.json rwrs-serverCreate a maps.json file in the same directory as the executable (or specify a custom path):
{
"maps": [
{
"name": "map9",
"path": "media/packages/vanilla.desert/maps/map9",
"image": "md5_1.png"
},
{
"name": "map10",
"path": "media/packages/vanilla.desert/maps/map10",
"image": "md5_2.png"
},
{
"name": "map5",
"path": "media/packages/vanilla.jungle/maps/map5",
"image": "md5_3.png"
}
]
}name: Human-readable map name (e.g., "map9")path: Full game path for the map (used as unique identifier)image: Image filename or CDN URL for the map preview
GET /api/maps
Returns a JSON response with all configured maps:
{
"maps": [
{
"name": "map9",
"path": "media/packages/vanilla.desert/maps/map9",
"image": "md5_1.png"
}
]
}{
"maps": [
{
"name": "desert_outpost",
"path": "media/packages/vanilla.desert/maps/map9",
"image": "desert_outpost.png"
}
]
}{
"maps": [
{
"name": "desert_outpost",
"path": "media/packages/vanilla.desert/maps/map9",
"image": "https://cdn.example.com/maps/desert_outpost.png"
}
]
}# Build optimized version
cargo build --releaseAfter building, the executable will be located at target/release/rwrs-server.
# Build Docker image
docker build -t rwrs-server .-
Build the server:
cargo build --release
-
Upload the built executable (
target/release/rwrs-server) to your server -
Create a
staticdirectory in the same location as the executable:mkdir static
-
Copy the rwrs-another-page frontend build files (from the
distdirectory) to thestaticdirectory:# Assuming you have the rwrs-another-page frontend build in ./dist cp -r /path/to/rwrs-another-page/dist/* ./static/
-
Copy or create the
maps.jsonconfiguration file in the same directory:# Copy the example maps.json cp maps.json ./deploy/maps.json # Or create a custom one based on the examples above
-
Set environment variables and run:
HOST=0.0.0.0 PORT=80 ./target/release/rwrs-server
There are two ways to deploy using Docker:
This approach runs the backend (rwrs-server) and frontend (rwrs-another-page) in separate containers.
-
Create a Docker network:
docker network create rwrs-network
-
Start the rwrs-server container:
docker pull zhaozisong0/rwrs-server:latest docker run -d --name rwrs-server --network rwrs-network \ -e HOST=0.0.0.0 \ -e PORT=80 \ -e ANDROID_REPO_URL=https://github.com/your-org/android-app \ -e WEB_REPO_URL=https://github.com/your-org/web-app \ zhaozisong0/rwrs-server:latest
-
Start the rwrs-another-page container:
docker pull zhaozisong0/rwrs-another-page:latest docker run -d --name rwrs-another-page --network rwrs-network -p 80:80 zhaozisong0/rwrs-another-page:latest
-
Configure a reverse proxy (like Nginx) to route:
/api/*requests to the rwrs-server container/*requests to the rwrs-another-page container
You can also deploy by serving the frontend directly from the rwrs-server's static directory:
-
Pull and run the rwrs-server container:
docker pull zhaozisong0/rwrs-server:latest docker run -d -p 80:80 --name rwrs-server \ -e HOST=0.0.0.0 \ -e PORT=80 \ -e ANDROID_REPO_URL=https://github.com/your-org/android-app \ -e WEB_REPO_URL=https://github.com/your-org/web-app \ zhaozisong0/rwrs-server:latest
-
Copy the frontend build to the container's static directory:
# Assuming you have the rwrs-another-page frontend build in ./dist docker cp ./dist/. rwrs-server:/static/Or mount the directory when starting the container:
docker run -d -p 80:80 --name rwrs-server \ -e HOST=0.0.0.0 \ -e PORT=80 \ -e ANDROID_REPO_URL=https://github.com/your-org/android-app \ -e WEB_REPO_URL=https://github.com/your-org/web-app \ -v $(pwd)/dist:/static \ -v $(pwd)/maps.json:/maps.json \ zhaozisong0/rwrs-server:latest
If you want to use a custom location for the maps configuration:
docker run -d -p 80:80 --name rwrs-server \
-e HOST=0.0.0.0 \
-e PORT=80 \
-e MAPS_CONFIG=/config/custom-maps.json \
-e ANDROID_REPO_URL=https://github.com/your-org/android-app \
-e WEB_REPO_URL=https://github.com/your-org/web-app \
-v $(pwd)/dist:/static \
-v $(pwd)/config/custom-maps.json:/config/custom-maps.json \
zhaozisong0/rwrs-server:latestAlternatively, use docker-compose:
version: '3'
services:
rwrs-server:
image: zhaozisong0/rwrs-server:latest
ports:
- "80:80"
environment:
- HOST=0.0.0.0
- PORT=80
- MAPS_CONFIG=/config/maps.json
- ANDROID_REPO_URL=https://github.com/your-org/android-app
- WEB_REPO_URL=https://github.com/your-org/web-app
restart: always
volumes:
# Mount frontend build to static directory
- ./dist:/static
# Mount maps configuration
- ./maps.json:/config/maps.jsonversion: '3'
services:
rwrs-server:
image: zhaozisong0/rwrs-server:latest
ports:
- "8080:5800"
environment:
- HOST=0.0.0.0
- PORT=5800
- MAPS_CONFIG=/app/config/custom-maps.json
- CACHE_DURATION_SECS=10
- ANDROID_REPO_URL=https://github.com/your-org/android-app
- WEB_REPO_URL=https://github.com/your-org/web-app
restart: always
volumes:
- ./dist:/static
- ./config/custom-maps.json:/app/config/custom-maps.json# Run all tests
cargo test
# Run tests with output
cargo test -- --nocapture
# Run specific test module
cargo test api_cache_tests
# Run integration tests only
cargo test --test '*'
# Run tests with coverage (requires cargo-llvm-cov)
cargo install cargo-llvm-cov
cargo llvm-cov --all-featuresThe project uses cargo-llvm-cov for code coverage reporting. Coverage reports are automatically generated on GitHub Actions and uploaded to Codecov.
To generate coverage locally:
# Install cargo-llvm-cov
cargo install cargo-llvm-cov
# Generate coverage report
cargo llvm-cov --all-features --html
# View the HTML report
open target/llvm-cov/html/index.html- Unit Tests: Located in
tests/directoryapi_cache_tests.rs- Tests for ApiCache functionalitymaps_config_tests.rs- Tests for MapsConfig loading and parsingapi_endpoints_tests.rs- Integration tests for API endpointstest_data/- Test configuration and data files
GitHub Actions automatically runs:
- Unit tests across multiple Rust versions (stable, beta, nightly)
- Code coverage reporting (Codecov)
- SonarQube quality analysis
- Clippy linting
- Code formatting checks
- Security audits
The project integrates with SonarQube/SonarCloud for comprehensive code quality analysis:
What it analyzes:
- Code coverage integration
- Code complexity and maintainability
- Security vulnerabilities
- Code smells and technical debt
- Duplicated code detection
Configuration:
- Analysis runs after all tests pass
- Only for main branch and pull requests
- Quality Gate enforcement can block merges if quality standards are not met
Setup Requirements:
- Set
SONAR_TOKENin GitHub repository secrets - Update
sonar-project.propertieswith your organization details - Configure SonarCloud/SonarQube project settings
- MIT.