better handling whenno cloudflare country header is given

This commit is contained in:
HF 2020-06-14 07:22:41 +02:00
parent e3be885cd0
commit c16c427ebd
2 changed files with 4 additions and 1 deletions

View File

@ -21,7 +21,7 @@ function authenticateClient(req) {
return new Promise(
((resolve) => {
router(req, {}, async () => {
const country = req.headers['cf-ipcountry'];
const country = req.headers['cf-ipcountry'] || 'xx';
const user = (req.user) ? req.user
: new User(null, getIPFromRequest(req));
user.country = country.toLowerCase();

View File

@ -12,6 +12,9 @@ import ccCoords from '../data/countrycode-coords-array.json';
* @return coords X/Y coordinates of the country on the canvas
*/
export function ccToCoords(cc: string) {
if (!cc) {
return [0, 0];
}
const country = cc.toLowerCase();
const coords = ccCoords[country];
return (coords) || [0, 0];