When working with an API such as start.gg's GraphQL API, managing your API key and making sure not to accidentally reveal it by packaging it with your application or sending it in plain text over the network from your users' computers is of great importance. This project aims to create an API proxy that stores your API key and takes care of communicating with the start.gg API without your API key ever touching your users' computers or networks.
To get your own copy of this proxy running, you will need a Cloudflare account to create a Worker on, and a start.gg account to get an API key from
Install Node using the instructions on their website, either a binary install or using your package manager of choice.
Wrangler is the command line tool used to manage Cloudflare Workers. Install it using your package manager of choice, or from npm using
npm install wrangler -g
Once installed, connect Wrangler to your Cloudflare account using
wrangler login
- Clone the repo
git clone https://github.com/jakobkg/startgg-api-proxy.git cd startgg-api-proxy
- Get your Cloudflare account ID by running
Then add the account ID to
wrangler whoami
wrangler.toml
account_id = "YOUR ID GOES HERE"
- Get your start.gg API key from your start.gg profile settings, then add this API key to the Worker with
wrangler secret put STARTGG_API_KEY
- Install dependencies (
typescript
andwebpack
for building,prettier
for code formatting)npm install
- All done! You can now run the proxy in a dev environment with
or publish the proxy to your Cloudflare Workers with
wrangler dev
wrangler publish
This proxy expects to receive a POST request with a body
{
groupId: number
}
The groupId
is used in a query to the start.gg GraphQL API, the exact query can be found in the query.ts source file. The response to this query is directly forwarded as a response to the original POST request.
The shape of the response from the start.gg API is consistent and can be consumed into a relatively simple object.
declare type PhaseResponse = {
data: {
phase?: Phase;
},
extensions: {
cacheControl: {
version: number;
hints?: Array<{
path: Array<string>;
maxAge: number;
scope: string;
}>
}
queryComplexity: number;
},
actionRecords: Array<{}>; // I have not been able to find documentation on this field,
// but have also never seen it populated
}
declare type Phase = {
name: string;
sets: {
nodes: Array<{
fullRoundText: string;
round: number;
slots: Array<{
entrant: {
name: string;
},
standing: {
stats: {
score: {
value: number;
}
}
}
}>
}>
}
}
For concrete response examples, please refer to the start.gg API explorer and schema reference
Distributed under the MIT License. See LICENSE
for more information.