Simple API to proxy and cache calls to Twitch's API to create a long term buffer and allow high volume of requests.
cp example.env .env
- Edit
.env
accordingly- You only need OAuth OR Client-ID tokens. OAuth allow for high volume of requests per minute.
docker build -t twitch-redis-cache .
docker run -d -p 3000:<port in .env> twitch-redis-cache
- Install Redis-Server
- Linux:
apt install redis-server
- Mac (via homebrew):
brew install redis
- Windows: https://redis.io/download
- Linux:
- git clone
https://github.com/UpDownLeftDie/twitch-redis-cache.git && cd twitch-redis-cache
npm install
cp example.env .env
- Edit
.env
accordingly- You only need OAuth OR Client-ID tokens
- OAuth allow for high volume of requests per minute.
npm start
- Clone or move the project to
/opt
(or where you like and edit the.service
file)mv twitch-redis-cache /opt/twitch-redis-cache
- Move the service file to
/lib/systemd/system
cd /opt/twitch-redis-cache && mv twitch-redis-cache.service /lib/systemd/system
- Edit the service file as needed
- Enable and start the service
sudo systemctl enable twitch-redis-cache.service && sudo systemctl start twitch-redis-cache.service
- Optional: make sure its running
sudo systemctl status twitch-redis-cache.service
Depending on where you're calling this API from you'll probably need it to be behind SSL. You could use Let's encrypt to get a certificate if you know how to set that up. A simpler method is using Cloudflare.
- Add a domain you purchased to Cloudflare.
- Cypto > SSL > Flexible
- This is because the server we're running the API on does not have a cert.
- Alternatively, if you can use a
Page Rule
to change the SSL setting if youre using a subdomain for this API.
- Set the port in the
.env
to80
(Docker: use-p 80:<port in .env>
) - Now you should be able to call it via
https://domain.com/userimage/TwitchUserNameHere
- Replace
request
package withnode-fetch
(or equivalent package) - Add in request queuing to Twitch if rate-limit is hit
- Switch to TypeScript (or even Golang)