Skip to content

Commit bd768f9

Browse files
committed
wip
Signed-off-by: Felipe Forbeck <[email protected]>
1 parent f9d7321 commit bd768f9

File tree

7 files changed

+11
-5
lines changed

7 files changed

+11
-5
lines changed

src/bindings.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ export interface Environment
1414
VERSION: string
1515
CONTENT_CLAIMS_SERVICE_URL?: string
1616
HONEYCOMB_API_KEY: string
17+
FF_TELEMETRY_ENABLED: string
1718
}

src/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ import {
2020
withVersionHeader,
2121
withAuthToken,
2222
withCarBlockHandler,
23+
withGatewayIdentity,
2324
withRateLimit,
2425
withEgressTracker,
26+
withEgressClient,
2527
withAuthorizedSpace,
2628
withLocator,
2729
withDelegationStubs
2830
} from './middleware/index.js'
2931
import { instrument } from '@microlabs/otel-cf-workers'
3032
import { NoopSpanProcessor } from '@opentelemetry/sdk-trace-base'
31-
import { withEgressClient } from './middleware/withEgressClient.js'
32-
import { withGatewayIdentity } from './middleware/withGatewayIdentity.js'
3333

3434
/**
3535
* @import {
@@ -106,7 +106,6 @@ function config(env, _trigger) {
106106
service: { name: 'freeway' },
107107
}
108108
}
109-
110109
export default process.env.FF_TELEMETRY_ENABLED === 'true'
111110
? instrument(handler, config)
112111
: handler

src/middleware/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ export { withAuthorizedSpace } from './withAuthorizedSpace.js'
77
export { withLocator } from './withLocator.js'
88
export { withEgressTracker } from './withEgressTracker.js'
99
export { withEgressClient } from './withEgressClient.js'
10-
export { withDelegationStubs } from './withDelegationStubs.js'
10+
export { withDelegationStubs } from './withDelegationStubs.js'
11+
export { withGatewayIdentity } from './withGatewayIdentity.js'

src/middleware/withAuthorizedSpace.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { Schema } from '@ucanto/client'
2828
* >
2929
* )}
3030
*/
31-
export function withAuthorizedSpace(handler) {
31+
export function withAuthorizedSpace (handler) {
3232
return async (request, env, ctx) => {
3333
const { locator, dataCid } = ctx
3434
const locRes = await locator.locate(dataCid.multihash)

src/middleware/withEgressClient.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ import { DID } from '@ucanto/core'
1818
*/
1919
export function withEgressClient(handler) {
2020
return async (req, env, ctx) => {
21+
if (env.FF_EGRESS_TRACKER_ENABLED !== 'true') {
22+
return handler(req, env, ctx)
23+
}
2124
const egressClient = await create(env, ctx)
2225
return handler(req, env, { ...ctx, egressClient })
2326
}

src/middleware/withEgressClient.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { GatewayIdentityContext } from './withGatewayIdentity.types.js'
44
import { DelegationsStorageContext } from './withAuthorizedSpace.types.js'
55

66
export interface Environment extends MiddlewareEnvironment {
7+
FF_EGRESS_TRACKER_ENABLED: string
78
GATEWAY_PRINCIPAL_KEY: string
89
UPLOAD_API_URL: string
910
UPLOAD_SERVICE_DID: string

test/miniflare/freeway.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ describe('freeway', () => {
5353
CONTENT_CLAIMS_SERVICE_URL: claimsService.url.toString(),
5454
CARPARK_PUBLIC_BUCKET_URL: url.toString()
5555
},
56+
inspectorPort: 9898,
5657
scriptPath: 'dist/worker.mjs',
5758
modules: true,
5859
compatibilityFlags: ['nodejs_compat'],

0 commit comments

Comments
 (0)