diff --git a/README.md b/README.md index a2b77d4..28fd189 100644 --- a/README.md +++ b/README.md @@ -159,9 +159,16 @@ in multiple locations, and stored as the new `GEOIP_ROOT` in `src/lookup.js` ## Testing in CLI +It is possible to run tests against a local gateway by passing `HTTP_GATEWAY`: + +```console +$ IPFS_GATEWAY="http://127.0.0.1:8080" npm test +``` + You can find an example of how to use this in [`example/lookup.js`](example/lookup.js), which you can use like this: ```bash +$ export IPFS_GATEWAY="http://127.0.0.1:8080" $ node example/lookup.js 66.6.44.4 Result: { "country_name": "USA", diff --git a/example/lookup.js b/example/lookup.js index dfd3fd4..b288ee8 100644 --- a/example/lookup.js +++ b/example/lookup.js @@ -1,8 +1,7 @@ import * as geoip from '../src/index.js' import { create } from 'ipfs-http-client' -// This CLI tool requires Kubo RPC on 127.0.0.1:5001 to be running -const ipfs = create(new URL('http://127.0.0.1:5001')) +const ipfsGw = process?.env?.IPFS_GATEWAY || 'https://ipfs.io' if (process.argv.length !== 3) { console.log('usage: node lookup.js ') @@ -11,14 +10,14 @@ if (process.argv.length !== 3) { (async function() { try { - const result = await geoip.lookup(ipfs, process.argv[2]) + const result = await geoip.lookup(ipfsGw, process.argv[2]) console.log('Result: ' + JSON.stringify(result, null, 2)) } catch (err) { console.log('Error: ' + err) } try { - const result = await geoip.lookupPretty(ipfs, '/ip4/' + process.argv[2]) + const result = await geoip.lookupPretty(ipfsGw, '/ip4/' + process.argv[2]) console.log('Pretty result: %s', result.formatted) } catch (err) { console.log('Error: ' + err) diff --git a/test/lookup.spec.js b/test/lookup.spec.js index be62e02..334f3fb 100644 --- a/test/lookup.spec.js +++ b/test/lookup.spec.js @@ -4,7 +4,7 @@ import * as geoip from '../src/index.js' describe('lookup via HTTP Gateway supporting application/vnd.ipld.raw responses', function () { this.timeout(100 * 1000) - const ipfsGW = 'https://ipfs.io' + const ipfsGW = process?.env?.IPFS_GATEWAY || 'https://ipfs.io' it('fails on 127.0.0.1', async () => { try {