A Cloudflare Worker that acts as a proxy server for the Riot Games API, managing rate limits and caching for better performance.
- Rate limiting for both clients and the server itself
- Caching successful API responses
- Extracting and setting the region for API requests
- Automatic handling of Riot API rate limits
-
Ensure you have Node.js, npm, and the Cloudflare Wrangler CLI installed on your system.
-
Clone the repository and navigate to the project folder:
git clone https://github.com/st4s1k/riot-api-proxy-server.git cd riot-api-proxy-server
-
Install the dependencies:
npm install
-
Configure the wrangler.toml file with your Cloudflare account ID and the appropriate API key.
-
Add your Riot Games API key as an environment variable in your Cloudflare Worker:
wrangler secret put API_KEY
-
Install dependencies:
npm install
-
Build the project:
npm run build
This command will compile TypeScript files and output the result to the
dist
directory. -
Run the project in development mode:
npm run start
This command will start the development server with live reloading, which will automatically recompile and restart the application when changes are detected.
-
Deploy the project:
npm run deploy
This command will deploy your application to Cloudflare Workers.
-
View real-time logs:
npm run tail
This command will display real-time logs from your Cloudflare Worker application.
-
Run tests:
npm test
This command will run the tests using Jest.
-
Run tests silently:
npm run test:silent
This command will run the tests using Jest without console output.
-
Run tests with logs output to a file in
./logs/
directory:npm run test:log
This command will run the tests and save the output to a log file located in the logs directory. The log file will be named with the format:
YYYY-MM-DD_HH-mm-ss.log
The worker configuration can be modified through environment variables or [vars]
section in the wrangler.toml
file:
DEFAULT_REGION
: Default region for Riot API requests (default: "euw1")CACHE_DURATION
: Cache duration in seconds (0 to disable) (default: 60 seconds)CLIENT_RATE_LIMIT_MULTIPLIER
: The multiplier is used to reduce the rate limit to avoid hitting the server rate limit (default: 0.5)
Create a .env
file in the project root directory and add the environment variables there. The .env
file is ignored by git and will not be committed to the repository. It should contain the Riot Games API key:
-
API_KEY
: Riot Games API keyAPI_KEY=RGAPI-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
This project is released under the MIT License. See the LICENSE file for details.