diff --git a/Dockerfile b/Dockerfile index b2f779c..b6ec811 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 \ No newline at end of file diff --git a/src/routes/runelite.ts b/src/routes/runelite.ts index 7d5b86e..e857c5b 100644 --- a/src/routes/runelite.ts +++ b/src/routes/runelite.ts @@ -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(); /** @@ -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.' }); } @@ -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.' }); }