Skip to content
This repository has been archived by the owner on Jul 22, 2020. It is now read-only.

Commit

Permalink
fix: add geoip whitelist file
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed Apr 28, 2019
1 parent 33b799d commit 3d1e266
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
21 changes: 21 additions & 0 deletions api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import _ from 'lodash';
import './inbound-stream';
import expressWs from 'express-ws';
import geoip from 'geoip-lite';
import YAML from 'yaml';
import fs from 'fs';
import assert from 'assert';

import config from './config';

Expand Down Expand Up @@ -253,8 +256,26 @@ app.get('/blk/:id', (req, res) => {
sendBlockResult(req, res);
});

let geoipWhitelist = {};
if (fs.existsSync('blockexplorer-geoip.yml')) {
try {
const file = fs.readFileSync('blockexplorer-geoip.yml', 'utf8');
geoipWhitelist = YAML.parse(file);
console.log('geoip whitelist:', geoipWhitelist);
assert(typeof geoipWhitelist === 'object');
} catch (err) {
console.log(err);
}
}

app.get('/geoip/:ip', (req, res) => {
const {ip} = req.params;

if (geoipWhitelist[ip]) {
res.send(JSON.stringify(geoipWhitelist[ip]) + '\n');
return;
}

const geo = geoip.lookup(ip);
if (geo === null) {
res.status(404).send('{"error":"not_found"}\n');
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"nocache": "^2.0.0",
"react-debounce-render": "^5.0.0",
"redis": "^2.8.0",
"serve": "^11.0.0"
"serve": "^11.0.0",
"yaml": "^1.5.0"
},
"devDependencies": {
"@material-ui/core": "^3.9.3",
Expand Down
14 changes: 14 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,13 @@
dependencies:
regenerator-runtime "^0.13.2"

"@babel/runtime@^7.4.3":
version "7.4.4"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.4.4.tgz#dc2e34982eb236803aa27a07fea6857af1b9171d"
integrity sha512-w0+uT71b6Yi7i5SE0co4NioIpSYS6lLiXvCzWzGSKvpK5vdQtCbICHMj+gbAKAOtxiV6HsVh/MBdaF9EQ6faSg==
dependencies:
regenerator-runtime "^0.13.2"

"@babel/template@^7.0.0", "@babel/template@^7.4.0":
version "7.4.0"
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.4.0.tgz#12474e9c077bae585c5d835a95c0b0b790c25c8b"
Expand Down Expand Up @@ -14378,6 +14385,13 @@ yallist@^3.0.0, yallist@^3.0.2:
resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.0.3.tgz#b4b049e314be545e3ce802236d6cd22cd91c3de9"
integrity sha512-S+Zk8DEWE6oKpV+vI3qWkaK+jSbIK86pCwe2IF/xwIpQ8jEuxpw9NyaGjmp9+BoJv5FV2piqCDcoCtStppiq2A==

yaml@^1.5.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.5.0.tgz#1d879dd069ce1036041c23229cb5d7ef47a58ec6"
integrity sha512-nKxSWOa7vxAP2pikrGxbkZsG/garQseRiLn9mIDjzwoQsyVy7ZWIpLoARejnINGGLA4fttuzRFFNxxbsztdJgw==
dependencies:
"@babel/runtime" "^7.4.3"

yargs-parser@^10.1.0:
version "10.1.0"
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-10.1.0.tgz#7202265b89f7e9e9f2e5765e0fe735a905edbaa8"
Expand Down

0 comments on commit 3d1e266

Please sign in to comment.