Something went wrong. Try again.
A Space host for truly public data
Something went wrong. Try again.
2.7 kB · 60 lines
TypeScript
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061export type Config = { /** Port to listen on. */ port: number /** * Public base URL of this host. Used as the origin of the `htu` that DPoP * proofs are checked against (set it whenever the host sits behind a * proxy), and to fill in the service endpoints in registration * instructions. When unset, the origin is taken from X-Forwarded-Proto / * Host on each request. */ publicUrl?: string /** Directory for the sqlite database. */ dataDir: string /** Lifetime of issued space credentials, in seconds. Long-lived by design: credentials are freely available. */ credentialTtlSeconds: number /** Lifetime of notify registrations, in seconds. */ registrationTtlSeconds: number /** Create a space on first credential request instead of returning SpaceNotFound. */ autoCreateSpaces: boolean /** Require a DPoP-bound space credential on listRepos / registerNotify / unregisterNotify. Off by default: this is a public host. */ requireCredentials: boolean /** Verify service-auth JWTs on incoming notifyWrite calls (requires network DID resolution). */ verifyNotifyAuth: boolean /** * Sign only with keys published in the authority's DID document (requires * network DID resolution). When false — dev only — the host signs with * ephemeral per-DID keys and consults no documents. */ verifyAuthority: boolean /** Sliding lifetime of pooled signing keys, in seconds. Keys in active use never expire. */ keyTtlSeconds: number /** Rate limit for POST /keys, per IP per hour. */ keyUploadsPerHour: number}
export function envConfig(env: NodeJS.ProcessEnv = process.env): Config { return { port: intEnv(env.PORT, 3000), publicUrl: env.PUBLIC_URL || undefined, dataDir: env.DATA_DIR ?? './data', credentialTtlSeconds: intEnv(env.CREDENTIAL_TTL_SECONDS, 30 * 24 * 60 * 60), registrationTtlSeconds: intEnv(env.REGISTRATION_TTL_SECONDS, 24 * 60 * 60), autoCreateSpaces: boolEnv(env.AUTO_CREATE_SPACES, true), requireCredentials: boolEnv(env.REQUIRE_CREDENTIALS, false), verifyNotifyAuth: boolEnv(env.VERIFY_NOTIFY_AUTH, true), verifyAuthority: boolEnv(env.VERIFY_AUTHORITY, true), keyTtlSeconds: intEnv(env.KEY_TTL_SECONDS, 90 * 24 * 60 * 60), keyUploadsPerHour: intEnv(env.KEY_UPLOADS_PER_HOUR, 10), }}
function intEnv(value: string | undefined, fallback: number): number { const parsed = value ? parseInt(value, 10) : NaN return Number.isFinite(parsed) ? parsed : fallback}
function boolEnv(value: string | undefined, fallback: boolean): boolean { if (value === undefined || value === '') return fallback return value !== 'false' && value !== '0'}