Skip to content

Commit 5976f65

Browse files
authored
feat: use blockstore sessions (#157)
Adds a `USE_SESSIONS` env var that controls whether to use blockstore sessions or not. The `session` option will be passed to `@helia/verified-fetch` accordingly.
1 parent 11c87ad commit 5976f65

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ $ npm start
9292
| `USE_DELEGATED_ROUTING` | Whether to use the delegated routing v1 API | `true` |
9393
| `DELEGATED_ROUTING_V1_HOST` | Hostname to use for delegated routing v1 | `https://delegated-ipfs.dev` |
9494
| `USE_DHT_ROUTING` | Whether to use @libp2p/kad-dht for routing when libp2p is enabled | `true` |
95+
| `USE_SESSIONS` | If true, use a blockstore session per IPFS/IPNS path | `true` |
9596

9697
<!--
9798
TODO: currently broken when used in docker, but they work when running locally (you can cache datastore and blockstore locally to speed things up if you want)

src/constants.ts

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export const FASTIFY_DEBUG = process.env.FASTIFY_DEBUG ?? ''
1515

1616
export const USE_SUBDOMAINS = process.env.USE_SUBDOMAINS !== 'false'
1717

18+
export const USE_SESSIONS = process.env.USE_SESSIONS !== 'false'
19+
1820
export const ECHO_HEADERS = process.env.ECHO_HEADERS === 'true'
1921

2022
/**

src/helia-http-gateway.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { raceSignal } from 'race-signal'
2-
import { USE_SUBDOMAINS } from './constants.js'
2+
import { USE_SUBDOMAINS, USE_SESSIONS } from './constants.js'
33
import { dnsLinkLabelEncoder, isInlinedDnsLink } from './dns-link-labels.js'
44
import { getFullUrlFromFastifyRequest, getRequestAwareSignal } from './helia-server.js'
55
import { getIpnsAddressDetails } from './ipns-address-utils.js'
@@ -89,7 +89,11 @@ export function httpGateway (opts: HeliaHTTPGatewayOptions): RouteOptions[] {
8989

9090
// if subdomains are disabled, have @helia/verified-fetch follow redirects
9191
// internally, otherwise let the client making the request do it
92-
const resp = await opts.fetch(url, { signal, redirect: USE_SUBDOMAINS ? 'manual' : 'follow' })
92+
const resp = await opts.fetch(url, {
93+
signal,
94+
redirect: USE_SUBDOMAINS ? 'manual' : 'follow',
95+
session: USE_SESSIONS
96+
})
9397

9498
await convertVerifiedFetchResponseToFastifyReply(url, resp, reply, {
9599
signal

0 commit comments

Comments
 (0)