Skip to content

Commit

Permalink
feat: default to public gateway
Browse files Browse the repository at this point in the history
We now can fetch raw blocks from a public gateway.
This will use public gateway if no API is provided.

License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
  • Loading branch information
lidel committed Sep 18, 2022
1 parent c10d1e3 commit 6c7d074
Show file tree
Hide file tree
Showing 8 changed files with 3,598 additions and 15,590 deletions.
32 changes: 29 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,20 @@ When using prebuilt bundle from CDN, `ipfs-geoip` will be exposed under `window.

## Usage

### With a public gateway (default)

If `ipfs` is `undefined` or a string with gateway URL, it will be used for
fetching data as [`application/vnd.ipld.raw`](https://www.iana.org/assignments/media-types/application/vnd.ipld.raw)
and parsing it as DAG-CBOR locally:

```js
const geoip = require('ipfs-geoip')
const ipfs = require('ipfs-http-client')()

const exampleIp = '66.6.44.4'

const ipfsGateway = 'https://ipfs.io'

try {
const result = await geoip.lookup(ipfs, exampleIp)
const result = await geoip.lookup(ipfsGateway, exampleIp)
console.log('Result: ', result)
} catch (err) {
console.log('Error: ' + err)
Expand All @@ -75,6 +81,26 @@ try {
}
```

### With JS-IPFS or Kubo RPC

It is also possible to use it with local or remote IPFS node that exposes
[`ipfs.block.get` Core JS API](https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/BLOCK.md#ipfsblockgetcid-options):

```js
const geoip = require('ipfs-geoip')
const exampleIp = '66.6.44.4'

const ipfsApi = require('ipfs-http-client')()

try {
const result = await geoip.lookup(ipfsApi, exampleIp)
console.log('Result: ', result)
} catch (err) {
console.log('Error: ' + err)
}
```


## API

### `lookup(ipfs, ip)`
Expand Down
2 changes: 1 addition & 1 deletion example/lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,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()
const ipfs = create(new URL('http://127.0.0.1:5001'))

if (process.argv.length !== 3) {
console.log('usage: node lookup.js <ip4-adr>')
Expand Down
Loading

0 comments on commit 6c7d074

Please sign in to comment.