Skip to content

Commit

Permalink
support http2 grpc client
Browse files Browse the repository at this point in the history
  • Loading branch information
devinivy committed Dec 26, 2023
1 parent 3b9a5cb commit e8258eb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
16 changes: 16 additions & 0 deletions packages/bsky/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export interface ServerConfigValues {
serverDid: string
feedGenDid?: string
dataplaneUrl: string
dataplaneHttpVersion?: '1.1' | '2'
dataplaneIgnoreBadTls?: boolean
didPlcUrl: string
handleResolveNameservers?: string[]
imgUriEndpoint?: string
Expand Down Expand Up @@ -36,10 +38,14 @@ export class ServerConfig {
const imgUriEndpoint = process.env.BSKY_IMG_URI_ENDPOINT
const blobCacheLocation = process.env.BSKY_BLOB_CACHE_LOC
const dataplaneUrl = process.env.BSKY_DATAPLANE_URL
const dataplaneHttpVersion = process.env.BSKY_DATAPLANE_HTTP_VERSION || '2'
const dataplaneIgnoreBadTls =
process.env.BSKY_DATAPLANE_IGNORE_BAD_TLS === 'true'
const adminPassword = process.env.BSKY_ADMIN_PASSWORD || 'admin'
const moderatorPassword = process.env.BSKY_MODERATOR_PASSWORD || undefined
const triagePassword = process.env.BSKY_TRIAGE_PASSWORD || undefined
assert(dataplaneUrl)
assert(dataplaneHttpVersion === '1.1' || dataplaneHttpVersion === '2')
return new ServerConfig({
version,
debugMode,
Expand All @@ -48,6 +54,8 @@ export class ServerConfig {
serverDid,
feedGenDid,
dataplaneUrl,
dataplaneHttpVersion,
dataplaneIgnoreBadTls,
didPlcUrl,
handleResolveNameservers,
imgUriEndpoint,
Expand Down Expand Up @@ -100,6 +108,14 @@ export class ServerConfig {
return this.cfg.dataplaneUrl
}

get dataplaneHttpVersion() {
return this.cfg.dataplaneHttpVersion
}

get dataplaneIgnoreBadTls() {
return this.cfg.dataplaneIgnoreBadTls
}

get handleResolveNameservers() {
return this.cfg.handleResolveNameservers
}
Expand Down
4 changes: 3 additions & 1 deletion packages/bsky/src/data-plane/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ type HttpVersion = '1.1' | '2'

export const createDataPlaneClient = (
baseUrl: string,
httpVersion: HttpVersion = '2',
opts: { httpVersion?: HttpVersion; rejectUnauthorized?: boolean },
) => {
const { httpVersion = '2', rejectUnauthorized = false } = opts
const transport = createConnectTransport({
baseUrl,
httpVersion,
nodeOptions: { rejectUnauthorized },
})
return createPromiseClient(Service, transport)
}
5 changes: 4 additions & 1 deletion packages/bsky/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ export class BskyAppView {
)
}

const dataplane = createDataPlaneClient(config.dataplaneUrl, '1.1')
const dataplane = createDataPlaneClient(config.dataplaneUrl, {
httpVersion: config.dataplaneHttpVersion,
rejectUnauthorized: config.dataplaneIgnoreBadTls,
})
const hydrator = new Hydrator(dataplane)
const views = new Views(imgUriBuilder)

Expand Down
1 change: 1 addition & 0 deletions packages/dev-env/src/bsky.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class TestBsky {
publicUrl: 'https://bsky.public.url',
serverDid,
dataplaneUrl: `http://localhost:${dataplanePort}`,
dataplaneHttpVersion: '1.1',
...cfg,
adminPassword: ADMIN_PASSWORD,
moderatorPassword: MOD_PASSWORD,
Expand Down

0 comments on commit e8258eb

Please sign in to comment.