Skip to content

Commit

Permalink
Add support for randomly ignoring a percentage of requests
Browse files Browse the repository at this point in the history
  • Loading branch information
lezed1 committed Nov 27, 2024
1 parent 29e7851 commit 2e9d39c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM node:16-alpine
FROM node:18-alpine

WORKDIR /home/node/app/

ADD package.json package-lock.json yarn.lock ./
ADD package.json yarn.lock ./

RUN yarn install
10 changes: 10 additions & 0 deletions src/routes/runelite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import { MusicService } from '../services/MusicService';
import { QuestService } from '../services/QuestService';
import { AllowedProfileType, ProfileType } from '../enum/ProfileType';

// 0.00 will handle no requests, 0.20 will handle 20% of requests, 1.00 will handle all requests
const PROPORTION_OF_SUBMIT_REQUESTS_TO_HANDLE = 1.00;
const PROPORTION_OF_GET_PROFILE_REQUESTS_TO_HANDLE = 1.00;

const router = express.Router();

/**
Expand All @@ -33,6 +37,9 @@ router.get('/version', (req, res) => {
* Submits player data from the RuneLite plugin to our database
*/
router.post('/submit', async (req, res) => {
if (Math.random() > PROPORTION_OF_SUBMIT_REQUESTS_TO_HANDLE) {
return res.status(500).json({ error: 'Internal error. Please try again later.' });
}
if (!req.body.username || !req.body.data || !req.body.data.varb || !req.body.data.varp) {
return res.status(400).json({ error: 'Missing required data.' });
}
Expand All @@ -48,6 +55,9 @@ router.post('/submit', async (req, res) => {
* Gets player data from our database
*/
router.get('/player/:username/:profile?', async (req, res) => {
if (Math.random() > PROPORTION_OF_GET_PROFILE_REQUESTS_TO_HANDLE) {
return res.status(500).json({ error: 'Internal error. Please try again later.' });
}
if (!req.params.username) {
return res.status(400).json({ error: 'Missing required data.' });
}
Expand Down

0 comments on commit 2e9d39c

Please sign in to comment.