Skip to content

Commit 811a74d

Browse files
committed
fix(ponder): require network in strict env
Document the Ponder runtime environment variables and make strict mode require PONDER_NETWORK alongside DATABASE_URL and RPC_URL. Signed-off-by: Jakub Sztandera <oss@kubuxu.com>
1 parent 77e74cf commit 811a74d

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

apps/ponder/README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,18 @@ pnpm --filter @filoz/repair-ponder dev:calibnet
2626
```
2727

2828
Set `DATABASE_URL` and `RPC_URL` to override the local defaults.
29-
Set `PONDER_STRICT_ENV=true` to require both variables, which is recommended for deployments.
29+
30+
Environment variables:
31+
32+
| Variable | Values | Default | Strict mode |
33+
| --- | --- | --- | --- |
34+
| `PONDER_NETWORK` | `mainnet`, `calibnet` | `mainnet` | Required |
35+
| `DATABASE_URL` | PostgreSQL connection string | `postgres://ponder:ponder@localhost:17825/ponder` | Required |
36+
| `RPC_URL` | Filecoin JSON-RPC URL | `http://localhost:1234/rpc/v1` | Required |
37+
| `PONDER_STRICT_ENV` | `true`, `1` | unset | Enables strict mode |
38+
39+
Set `PONDER_STRICT_ENV=true` to require `PONDER_NETWORK`, `DATABASE_URL`, and `RPC_URL`, which is recommended for
40+
deployments.
3041

3142
## Networks
3243

apps/ponder/ponder.config.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ import { rpcTransport } from './src/rpc.ts'
66
const DEFAULT_DATABASE_URL = 'postgres://ponder:ponder@localhost:17825/ponder'
77
const DEFAULT_RPC_URL = 'http://localhost:1234/rpc/v1'
88

9-
function parseNetwork(value: string | undefined): NetworkName {
10-
if (value === undefined || value === '') return 'mainnet'
9+
function parseNetwork(value: string | undefined, strict: boolean): NetworkName {
10+
if (value === undefined || value === '') {
11+
if (strict) throw new Error('PONDER_NETWORK is required when PONDER_STRICT_ENV=true')
12+
return 'mainnet'
13+
}
1114
if (value === 'mainnet' || value === 'calibnet') return value
1215
throw new Error(`Unsupported PONDER_NETWORK "${value}". Expected "mainnet" or "calibnet".`)
1316
}
@@ -23,9 +26,9 @@ function env(name: string, fallback: string, strict: boolean): string {
2326
return fallback
2427
}
2528

26-
const networkName = parseNetwork(process.env.PONDER_NETWORK)
27-
const network = NETWORKS[networkName]
2829
const strictEnv = parseStrictEnv(process.env.PONDER_STRICT_ENV)
30+
const networkName = parseNetwork(process.env.PONDER_NETWORK, strictEnv)
31+
const network = NETWORKS[networkName]
2932

3033
export default createConfig({
3134
database: {

0 commit comments

Comments
 (0)