-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Polishing nodejs-client and mix-fetch-node
Signed-off-by: Sebastian Martinez <[email protected]>
- Loading branch information
1 parent
7129de4
commit 06a96fa
Showing
28 changed files
with
1,257 additions
and
191 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
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
2 changes: 1 addition & 1 deletion
2
...ges/mix-fetch-node/internal-dev/index.mjs → ...cript/examples/mix-fetch/node-js/index.js
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
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 @@ | ||
{ | ||
"name": "@nymproject/mix-fetch-node-js-example", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"scripts": { | ||
"start": "node index.js", | ||
"start:server": "node server.js", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"dependencies": { | ||
"@nymproject/mix-fetch-node-commonjs": "^1.2.1-rc.2" | ||
} | ||
} |
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,55 @@ | ||
const express = require('express'); | ||
const { mixFetch } = require('@nymproject/mix-fetch-node-commonjs'); | ||
|
||
const app = express(); | ||
app.use(express.static('public')); | ||
|
||
app.get('/nym-fetch', async (req, res) => { | ||
try { | ||
const args = { | ||
mode: 'unsafe-ignore-cors', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}; | ||
|
||
const url = req.query.url; | ||
|
||
if (!url) { | ||
return res.status(400).send('input a valid url'); | ||
} | ||
|
||
const extra = { | ||
hiddenGateways: [ | ||
{ | ||
owner: 'n1ns3v70ul9gnl9l9fkyz8cyxfq75vjcmx8el0t3', | ||
host: 'sandbox-gateway1.nymtech.net', | ||
explicitIp: '35.158.238.80', | ||
identityKey: 'HjNEDJuotWV8VD4ufeA1jeheTnfNJ7Jorevp57hgaZua', | ||
sphinxKey: 'BoXeUD7ERGmzRauMjJD3itVNnQiH42ncUb6kcVLrb3dy', | ||
}, | ||
], | ||
}; | ||
|
||
const mixFetchOptions = { | ||
nymApiUrl: 'https://sandbox-nym-api1.nymtech.net/api', | ||
preferredGateway: 'HjNEDJuotWV8VD4ufeA1jeheTnfNJ7Jorevp57hgaZua', | ||
preferredNetworkRequester: | ||
'AzGdJ4MU78Ex22NEWfeycbN7bt3PFZr1MtKstAdhfELG.GSxnKnvKPjjQm3FdtsgG5KyhP6adGbPHRmFWDH4XfUpP@HjNEDJuotWV8VD4ufeA1jeheTnfNJ7Jorevp57hgaZua', | ||
mixFetchOverride: { | ||
requestTimeoutMs: 60_000, | ||
}, | ||
forceTls: false, | ||
extra, | ||
}; | ||
|
||
const response = await mixFetch(url, args, mixFetchOptions); | ||
const json = await response.json(); | ||
res.send(json); | ||
} catch (error) { | ||
console.log(error); | ||
res.status(500).send(error.message); | ||
} | ||
}); | ||
|
||
app.listen(3000, () => console.log('Server running on port 3000')); |
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
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
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
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
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
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
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,4 +1,5 @@ | ||
import './polyfill'; | ||
|
||
import { loadWasm } from './wasm-loading'; | ||
import { run } from './main'; | ||
|
||
|
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
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
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
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,25 @@ | ||
const { createNymMixnetClient } = require('../dist/cjs/index.js'); | ||
|
||
(async () => { | ||
const nym = await createNymMixnetClient(); | ||
|
||
nym.events.subscribeToTextMessageReceivedEvent(async ({ args: { payload, mimeType } }) => { | ||
console.log(`received message: ${payload}`); | ||
console.log(`with mimeType: ${mimeType}`); | ||
}); | ||
|
||
// start the client and connect to a gateway | ||
await nym.client.start({ | ||
nymApiUrl: 'https://validator.nymtech.net/api/', | ||
clientId: 'my-client', | ||
}); | ||
|
||
nym.events.subscribeToConnected(async (e) => { | ||
// send a message to yourself | ||
const message = 'Hello'; | ||
const recipient = await nym.client.selfAddress(); | ||
console.log('main thread address: ', recipient); | ||
console.log(`sending "${message}" to ourselves...`); | ||
await nym.client.send({ payload: { message, mimeType: 'text/plain' }, recipient }); | ||
}); | ||
})(); |
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
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
Oops, something went wrong.