generated from libp2p/js-libp2p-example-fork-go-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: switch delegated routing example to vite (#181)
React-scripts have a dep conflict with react-native that's unlikely to be resolved so switch to vite.
- Loading branch information
1 parent
5681de2
commit 0dc653b
Showing
7 changed files
with
121 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||
<meta name="theme-color" content="#000000"> | ||
<title>Delegated Routing</title> | ||
<link rel="stylesheet" type="text/css" href="main.css"> | ||
</head> | ||
<body> | ||
<div> | ||
<header class="center"> | ||
<h1>Delegated Routing</h1> | ||
</header> | ||
<section class="center"> | ||
<form id="findProvidersForm"> | ||
<label> | ||
Find providers of CID: | ||
<input type="text" value="" id="find-providers-input" /> | ||
<input type="submit" value="Find Providers" id="find-providers-button" /> | ||
</label> | ||
</form> | ||
<form id="findPeerForm"> | ||
<label> | ||
Find peer: | ||
<input type="text" value="" id="find-peer-input" /> | ||
<input type="submit" value="Find PeerInfo" id="find-peer-button" /> | ||
</label> | ||
</form> | ||
</section> | ||
<section id="loading-notification"> | ||
<div class="lds-ripple"><div></div><div></div></div> | ||
</section> | ||
<section> | ||
<pre id="output"> | ||
</pre> | ||
</section> | ||
</div> | ||
<script src="index.js" type="module"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,60 @@ | ||
/* eslint-disable no-console */ | ||
import 'react' | ||
import ReactDOM from 'react-dom' | ||
import App from './App.js' // eslint-disable-line no-unused-vars | ||
|
||
ReactDOM.render(<App />, document.getElementById('root')) | ||
import { createDelegatedRoutingV1HttpApiClient } from '@helia/delegated-routing-v1-http-api-client' | ||
import { peerIdFromString } from '@libp2p/peer-id' | ||
import { createLibp2p } from 'libp2p' | ||
import { CID } from 'multiformats/cid' | ||
|
||
const DOM = { | ||
findProvidersInput: () => document.getElementById('find-providers-input'), | ||
findProvidersButton: () => document.getElementById('find-providers-button'), | ||
|
||
findPeerInput: () => document.getElementById('find-peer-input'), | ||
findPeerButton: () => document.getElementById('find-peer-button'), | ||
|
||
loadingNotificationElement: () => document.getElementById('loading-notification'), | ||
|
||
output: () => document.getElementById('output') | ||
} | ||
|
||
const libp2p = await createLibp2p({ | ||
services: { | ||
delegatedRouting: () => createDelegatedRoutingV1HttpApiClient('http://127.0.0.1:9832') | ||
} | ||
}) | ||
|
||
// find providers | ||
DOM.findProvidersButton().onclick = async (event) => { | ||
event.preventDefault() | ||
DOM.loadingNotificationElement().className = 'loading' | ||
|
||
try { | ||
const cid = CID.parse(DOM.findProvidersInput().value) | ||
const providers = [] | ||
DOM.output().innerText = '' | ||
|
||
for await (const provider of libp2p.contentRouting.findProviders(cid)) { | ||
providers.push(provider) | ||
|
||
DOM.output().innerText = JSON.stringify(providers, null, 2) | ||
} | ||
} finally { | ||
DOM.loadingNotificationElement().className = '' | ||
} | ||
} | ||
|
||
// find peer | ||
DOM.findPeerButton().onclick = async (event) => { | ||
event.preventDefault() | ||
DOM.loadingNotificationElement().className = 'loading' | ||
|
||
try { | ||
const peerId = peerIdFromString(DOM.findPeerInput().value) | ||
DOM.output().innerText = '' | ||
const peerInfo = await libp2p.peerRouting.findPeer(peerId) | ||
|
||
DOM.output().innerText = JSON.stringify(peerInfo, null, 2) | ||
} finally { | ||
DOM.loadingNotificationElement().className = '' | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export default { | ||
build: { | ||
target: 'es2022', | ||
outDir: '../dist', | ||
emptyOutDir: true | ||
}, | ||
optimizeDeps: { | ||
esbuildOptions: { target: 'es2022', supported: { bigint: true } } | ||
}, | ||
server: { | ||
open: true | ||
}, | ||
root: './src' | ||
} |