Fixes #22 adding User-Agent request header to bypass Incapsula protection of OSRS hiscore pages

This commit is contained in:
molo-pl
2021-01-12 15:37:19 +01:00
parent 0f68c1995c
commit cf8a4cc26e
4 changed files with 43 additions and 10 deletions

View File

@@ -1,3 +1,4 @@
import axios from 'axios';
import { Gamemode, SkillName, ActivityName } from '../types';
import {
GAMEMODE_URL,
@@ -6,6 +7,7 @@ import {
SKILLS,
ACTIVITIES,
} from './constants';
const ua = require('useragent-generator');
export const getStatsURL = (gamemode: Gamemode, rsn: string) =>
`${GAMEMODE_URL[gamemode]}${STATS_URL}${encodeURIComponent(rsn)}`;
@@ -45,3 +47,12 @@ export const rsnFromElement = (el: Element | null) => {
const { innerHTML } = el || {};
return innerHTML?.replace(/\uFFFD/g, ' ') || '';
};
export const httpGet = (url: string) => {
return axios.get(url, {
headers: {
// without User-Agent header requests may be rejected by DDoS protection mechanism
'User-Agent': ua.firefox(80)
}
});
};