Skip to content

Commit

Permalink
switch to 'cross-fetch' instead of 'request' (#6)
Browse files Browse the repository at this point in the history
* Replaces `request` with `cross-fetch`, and isomorphic fetch library
  - The `RequestOptions` type is a mix of the browser and `node-fetch` options, so that server-side code can set things like the `agent` for keepalive, but it should have no effect in browser code
  - The `lodash` dependency was removed from the `thrift-server-core` library, because all it was used for was doing "deep merges" on the client, which weren't needed. Instead, a new function to merge together request options was added, with special logic for the `Headers` values (which can't utilize object spread).
  - The `response.arrayBuffer()` function is used to get an `ArrayBuffer` and convert the binary response into a Node `Buffer`, which is what the generated code expects to use when sending requests through the connection. We'll need to polyfill that with Webpack, but it should be just fine.
* Removed all uses of the `url.parse` and `url.format` deprecated functions and replaced them with the WHATWG URL API
* Fixed a number of tests and cleaned them up with the right response types
  • Loading branch information
strmer15 authored Jan 25, 2022
2 parents 51f19eb + 7fb6bb6 commit baa0b58
Show file tree
Hide file tree
Showing 23 changed files with 1,895 additions and 1,023 deletions.
376 changes: 9 additions & 367 deletions packages/thrift-client-zipkin-filter/package-lock.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions packages/thrift-client-zipkin-filter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@
"typescript": "~4.4.4"
},
"dependencies": {
"@types/request": "^2.48.8",
"request": "^2.88.2",
"cross-fetch": "^3.1.4",
"zipkin": "^0.22.0"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Instrumentation, TraceId, Tracer } from 'zipkin'

import { CoreOptions } from 'request'

import {
formatUrl,
IRequestContext,
Expand All @@ -15,6 +13,7 @@ import {
IThriftClientFilter,
IThriftRequest,
NextFunction,
RequestOptions,
} from '@statestitle/thrift-client'

import {
Expand Down Expand Up @@ -65,7 +64,7 @@ function readRequestContext(
}

function readRequestHeaders(
request: IThriftRequest<CoreOptions>,
request: IThriftRequest<RequestOptions>,
): IRequestHeaders {
if (request.context && request.context.headers) {
return request.context.headers
Expand All @@ -78,7 +77,7 @@ export function ThriftClientZipkinFilter<Context extends IRequest>({
localServiceName,
remoteServiceName,
tracerConfig = {},
}: IZipkinClientOptions): IThriftClientFilter<CoreOptions> {
}: IZipkinClientOptions): IThriftClientFilter<RequestOptions> {
const serviceName: string = remoteServiceName || localServiceName
const tracer: Tracer = getTracerForService(serviceName, tracerConfig)
const instrumentation = new Instrumentation.HttpClient({
Expand All @@ -90,8 +89,8 @@ export function ThriftClientZipkinFilter<Context extends IRequest>({
return {
methods: [],
handler(
request: IThriftRequest<CoreOptions>,
next: NextFunction<CoreOptions>,
request: IThriftRequest<RequestOptions>,
next: NextFunction<RequestOptions>,
): Promise<IRequestResponse> {
const requestHeaders: IRequestHeaders = readRequestHeaders(request)
const requestContext: IRequestContext = readRequestContext(
Expand Down
Loading

0 comments on commit baa0b58

Please sign in to comment.