Skip to content

Commit baa0b58

Browse files
authored
switch to 'cross-fetch' instead of 'request' (#6)
* 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
2 parents 51f19eb + 7fb6bb6 commit baa0b58

File tree

23 files changed

+1895
-1023
lines changed

23 files changed

+1895
-1023
lines changed

packages/thrift-client-zipkin-filter/package-lock.json

+9-367
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/thrift-client-zipkin-filter/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@
4444
"typescript": "~4.4.4"
4545
},
4646
"dependencies": {
47-
"@types/request": "^2.48.8",
48-
"request": "^2.88.2",
47+
"cross-fetch": "^3.1.4",
4948
"zipkin": "^0.22.0"
5049
}
5150
}

packages/thrift-client-zipkin-filter/src/main/ThriftClientZipkinFilter.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { Instrumentation, TraceId, Tracer } from 'zipkin'
22

3-
import { CoreOptions } from 'request'
4-
53
import {
64
formatUrl,
75
IRequestContext,
@@ -15,6 +13,7 @@ import {
1513
IThriftClientFilter,
1614
IThriftRequest,
1715
NextFunction,
16+
RequestOptions,
1817
} from '@statestitle/thrift-client'
1918

2019
import {
@@ -65,7 +64,7 @@ function readRequestContext(
6564
}
6665

6766
function readRequestHeaders(
68-
request: IThriftRequest<CoreOptions>,
67+
request: IThriftRequest<RequestOptions>,
6968
): IRequestHeaders {
7069
if (request.context && request.context.headers) {
7170
return request.context.headers
@@ -78,7 +77,7 @@ export function ThriftClientZipkinFilter<Context extends IRequest>({
7877
localServiceName,
7978
remoteServiceName,
8079
tracerConfig = {},
81-
}: IZipkinClientOptions): IThriftClientFilter<CoreOptions> {
80+
}: IZipkinClientOptions): IThriftClientFilter<RequestOptions> {
8281
const serviceName: string = remoteServiceName || localServiceName
8382
const tracer: Tracer = getTracerForService(serviceName, tracerConfig)
8483
const instrumentation = new Instrumentation.HttpClient({
@@ -90,8 +89,8 @@ export function ThriftClientZipkinFilter<Context extends IRequest>({
9089
return {
9190
methods: [],
9291
handler(
93-
request: IThriftRequest<CoreOptions>,
94-
next: NextFunction<CoreOptions>,
92+
request: IThriftRequest<RequestOptions>,
93+
next: NextFunction<RequestOptions>,
9594
): Promise<IRequestResponse> {
9695
const requestHeaders: IRequestHeaders = readRequestHeaders(request)
9796
const requestContext: IRequestContext = readRequestContext(

0 commit comments

Comments
 (0)