Skip to content

Commit f94d900

Browse files
mfahampshiremfahampshire
andauthored
update mixfetch docs (#4614)
* * added info on gateway habourmaster * fixed broken examples with new infra addresses * bump node version in ts sdk docs ci script --------- Co-authored-by: mfahampshire <[email protected]>
1 parent 579e41d commit f94d900

File tree

5 files changed

+41
-20
lines changed

5 files changed

+41
-20
lines changed

.github/workflows/ci-sdk-docs-typescript.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- uses: rlespinasse/[email protected]
1818
- uses: actions/setup-node@v3
1919
with:
20-
node-version: 18
20+
node-version: 18.17
2121
- name: Install Rust stable
2222
uses: actions-rs/toolchain@v1
2323
with:

sdk/typescript/docs/code-examples/mixfetch-example-code.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ const args = { mode: 'unsafe-ignore-cors' };
1515

1616

1717
const mixFetchOptions: SetupMixFetchOps = {
18-
preferredGateway: 'E3mvZTHQCdBvhfr178Swx9g4QG3kkRUun7YnToLMcMbM', // with WSS
18+
preferredGateway: '983r9LKDT9UUxx4Zsn2AH49poJ7Ep24ueR8ENfWFgCX6', // with WSS
1919
preferredNetworkRequester:
20-
'GiRjFWrMxt58pEMuusm4yT3RxoMD1MMPrR9M2N4VWRJP.3CNZBPq4vg7v7qozjGjdPMXcvDmkbWPCgbGCjQVw9n6Z@2xU4CBE6QiiYt6EyBXSALwxkNvM7gqJfjHXaMkjiFmYW',
20+
'DxAc9J4eqREc8hYfDobkSc81JLkmmrhJ77zJvHShUPoi.92bnebXtBuwKiYycrpioaAiYgta5hHWkys5aSGBQg5av@983r9LKDT9UUxx4Zsn2AH49poJ7Ep24ueR8ENfWFgCX6',
2121
mixFetchOverride: {
2222
requestTimeoutMs: 60_000,
2323
},

sdk/typescript/docs/components/mix-fetch.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ const defaultUrl = 'https://nymtech.net/favicon.svg';
1313
const args = { mode: 'unsafe-ignore-cors' };
1414

1515
const mixFetchOptions: SetupMixFetchOps = {
16-
preferredGateway: 'E3mvZTHQCdBvhfr178Swx9g4QG3kkRUun7YnToLMcMbM', // with WSS
16+
preferredGateway: '983r9LKDT9UUxx4Zsn2AH49poJ7Ep24ueR8ENfWFgCX6', // with WSS
1717
preferredNetworkRequester:
18-
'GiRjFWrMxt58pEMuusm4yT3RxoMD1MMPrR9M2N4VWRJP.3CNZBPq4vg7v7qozjGjdPMXcvDmkbWPCgbGCjQVw9n6Z@2xU4CBE6QiiYt6EyBXSALwxkNvM7gqJfjHXaMkjiFmYW',
18+
'DxAc9J4eqREc8hYfDobkSc81JLkmmrhJ77zJvHShUPoi.92bnebXtBuwKiYycrpioaAiYgta5hHWkys5aSGBQg5av@983r9LKDT9UUxx4Zsn2AH49poJ7Ep24ueR8ENfWFgCX6',
1919
mixFetchOverride: {
2020
requestTimeoutMs: 60_000,
2121
},

sdk/typescript/docs/pages/examples/mix-fetch.mdx

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Callout } from 'nextra/components'
44

55
An easy way to secure parts or all of your web app is to replace calls to [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch) with `mixFetch`:
66

7-
MixFetch works the same as vanilla `fetch` as it's a proxied wrapper around the original function.
7+
MixFetch works the same as vanilla `fetch` as it's a proxied wrapper around the original function.
88
Sounds great, are there any catches? Well, there are a few (for now):
99

1010
1. Currently, the operators of Network Requesters that make the final request at the egress part of the Nym mixnet to
@@ -16,30 +16,38 @@ in combination with their own configuration. If you are trying to access somethi
1616
3. If you are using `mixFetch` in a web app with HTTPS you will need to use a gateway that has Secure Websockets to
1717
avoid getting a [mixed content](https://developer.mozilla.org/en-US/docs/Web/Security/Mixed_content) error.
1818

19-
4. For now, mixfetch doesn't work with SURBS, altough this may change in the future.
19+
4. For now, mixfetch doesn't work with SURBS, altough this may change in the future.
2020

2121

2222
Read [this article](https://blog.nymtech.net/mixfetch-like-the-fetch-api-but-via-the-mixnet-82acfd435c62) to learn more about mixFetch.
2323

2424
<Callout type="info" emoji="ℹ️">
25-
We are currently working on a feature that adds a Secure Websocket (WSS) listener with HTTPS (automatically generated with LetsEncrypt) to Nym's
26-
gateways.
27-
While we are adding this feature, you can use a gateway that has Caddy providing HTTPS/WSS by adding this to the options when setting up `mixFetch`:
25+
Right now Gateways are not required to run a Secure Websocket (WSS) listener, so only a subset of nodes running in Gateway mode have configured their nodes to do so.
26+
27+
For the moment you have to select a Gateway that has WSS enabled from [this list](https://harbourmaster.nymtech.net/v1/services?wss=true).
28+
29+
You can also find WSS-enabled nodes by querying the `gateways/described` endpoint on the Nym API, either via the [Swagger webpage](https://validator.nymtech.net/api/swagger/index.html) or with `curl`:
30+
31+
```
32+
curl -X 'GET' \
33+
'https://validator.nymtech.net/api/v1/gateways/described' \
34+
-H 'accept: application/json'
35+
```
2836
</Callout>
2937

3038
```ts
3139
// For mainnet
3240
import type { SetupMixFetchOps } from '@nymproject/mix-fetch';
3341

3442
const mixFetchOptions: SetupMixFetchOps = {
35-
preferredGateway: 'E3mvZTHQCdBvhfr178Swx9g4QG3kkRUun7YnToLMcMbM', // with WSS
43+
preferredGateway: '983r9LKDT9UUxx4Zsn2AH49poJ7Ep24ueR8ENfWFgCX6', // with WSS
3644
preferredNetworkRequester:
37-
'GiRjFWrMxt58pEMuusm4yT3RxoMD1MMPrR9M2N4VWRJP.3CNZBPq4vg7v7qozjGjdPMXcvDmkbWPCgbGCjQVw9n6Z@2xU4CBE6QiiYt6EyBXSALwxkNvM7gqJfjHXaMkjiFmYW',
45+
'DxAc9J4eqREc8hYfDobkSc81JLkmmrhJ77zJvHShUPoi.92bnebXtBuwKiYycrpioaAiYgta5hHWkys5aSGBQg5av@983r9LKDT9UUxx4Zsn2AH49poJ7Ep24ueR8ENfWFgCX6',
3846
mixFetchOverride: {
3947
requestTimeoutMs: 60_000,
4048
},
4149
forceTls: true, // force WSS
42-
extra: {},
50+
extra: {},
4351
};
4452
```
4553

@@ -53,7 +61,7 @@ npm create vite@latest
5361
During the environment setup, choose React and subsequently opt for Typescript if you want your application to function smoothly following this tutorial. Next, navigate to your application directory and run the following commands:
5462
```bash
5563
cd < YOUR_APP >
56-
npm i
64+
npm i
5765
npm run dev
5866
```
5967

@@ -74,17 +82,17 @@ import { mixFetch } from "@nymproject/mix-fetch-full-fat";
7482

7583
##### Example: using the `mixFetch` client:
7684

77-
`Get` and `Post` outputs will be observable from your console.
85+
`Get` and `Post` outputs will be observable from your console.
7886

7987
```ts
8088
import "./App.css";
8189
import { mixFetch, SetupMixFetchOps } from '@nymproject/mix-fetch-full-fat';
8290
import React from 'react';
8391

8492
const mixFetchOptions: SetupMixFetchOps = {
85-
preferredGateway: 'E3mvZTHQCdBvhfr178Swx9g4QG3kkRUun7YnToLMcMbM', // with WSS
93+
preferredGateway: '983r9LKDT9UUxx4Zsn2AH49poJ7Ep24ueR8ENfWFgCX6', // with WSS
8694
preferredNetworkRequester:
87-
'GiRjFWrMxt58pEMuusm4yT3RxoMD1MMPrR9M2N4VWRJP.3CNZBPq4vg7v7qozjGjdPMXcvDmkbWPCgbGCjQVw9n6Z@2xU4CBE6QiiYt6EyBXSALwxkNvM7gqJfjHXaMkjiFmYW',
95+
'DxAc9J4eqREc8hYfDobkSc81JLkmmrhJ77zJvHShUPoi.92bnebXtBuwKiYycrpioaAiYgta5hHWkys5aSGBQg5av@983r9LKDT9UUxx4Zsn2AH49poJ7Ep24ueR8ENfWFgCX6',
8896
mixFetchOverride: {
8997
requestTimeoutMs: 60_000,
9098
},
@@ -113,7 +121,7 @@ export function HttpGET() {
113121
export function HttpPOST() {
114122
async function post () {
115123
//Make sure the URL is whitelisted (see 'standard allowed list') otherwise you will get a network requester filter check error
116-
const apiResponse = await mixFetch('https://postman-echo.com/post', {
124+
const apiResponse = await mixFetch('https://httpbin.org/post', {
117125
method: 'POST',
118126
body: JSON.stringify({ foo: 'bar' }),
119127
headers: { 'Content-Type': 'application/json' }

sdk/typescript/docs/pages/playground/mixfetch.mdx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,22 @@
33
import { MixFetch } from '../../components/mix-fetch'
44
import Box from '@mui/material/Box';
55
import FormattedMixFetchExampleCode from '../../code-examples/mixfetch-example-code.mdx';
6+
import { Callout } from 'nextra/components'
7+
8+
<Callout type="info" emoji="ℹ️">
9+
Right now Gateways are not required to run a Secure Websocket (WSS) listener, so only a subset of nodes running in Gateway mode have configured their nodes to do so.
10+
11+
For the moment you have to select a Gateway that has WSS enabled from [this list](https://harbourmaster.nymtech.net/v1/services?wss=true).
12+
13+
You can also find WSS-enabled nodes by querying the `gateways/described` endpoint on the Nym API and filtering for `wss_port`, either via the [Swagger webpage](https://validator.nymtech.net/api/swagger/index.html) or with `curl`:
14+
15+
```
16+
curl -X 'GET' \
17+
'https://validator.nymtech.net/api/v1/gateways/described' \
18+
-H 'accept: application/json'
19+
```
20+
</Callout>
621

7-
Look in the [standard allowed list](https://nymtech.net/.wellknown/network-requester/standard-allowed-list.txt) and
8-
use the playground below to do a HTTP GET request to any host in the allowed list:
922

1023
<MixFetch />
1124
<FormattedMixFetchExampleCode />

0 commit comments

Comments
 (0)