Skip to content

Commit

Permalink
Replace proper-url-join dependency with global.URL
Browse files Browse the repository at this point in the history
  • Loading branch information
i-like-robots committed Jan 7, 2024
1 parent e439436 commit b694310
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 78 deletions.
69 changes: 1 addition & 68 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions package.json
Expand Up @@ -47,11 +47,9 @@
"homepage": "https://github.com/i-like-robots/hardened-fetch",
"dependencies": {
"@types/http-errors": "^2.0.4",
"@types/proper-url-join": "^2.1.4",
"@web3-storage/parse-link-header": "^3.1.0",
"bottleneck": "^2.19.5",
"http-errors": "^2.0.0",
"proper-url-join": "^2.1.1"
"http-errors": "^2.0.0"
},
"devDependencies": {
"@types/node": "^18.11.8",
Expand Down
7 changes: 2 additions & 5 deletions src/HardenedFetch.ts
@@ -1,4 +1,3 @@
import join from 'proper-url-join'
import Bottleneck from 'bottleneck'
import { parseLinkHeader } from '@web3-storage/parse-link-header'
import { handleFailed } from './handleFailed.js'
Expand Down Expand Up @@ -34,16 +33,14 @@ export class HardenedFetch {
}

fetch(url: string, init: RequestInit = {}, timeout: number = 30_000) {
if (this.options.baseUrl && !url.startsWith('http')) {
url = join(this.options.baseUrl, url)
}
const resolvedUrl = new URL(url, this.options.baseUrl)

if (this.options.defaultHeaders) {
const headers = Object.assign({}, this.options.defaultHeaders, init.headers)
init = Object.assign({}, init, { headers })
}

return this.queue.schedule(makeRequest, url, init, timeout)
return this.queue.schedule(makeRequest, resolvedUrl, init, timeout)
}

async *paginatedFetch(url: string, init: RequestInit = {}, timeout: number = 30_000) {
Expand Down
4 changes: 2 additions & 2 deletions src/makeRequest.ts
@@ -1,9 +1,9 @@
import createHttpError from 'http-errors'

export async function makeRequest(
url: string,
url: string | URL,
init: RequestInit = {},
timeout = 9000
timeout = 30_000
): Promise<Response> {
const signal = AbortSignal.timeout(timeout)
const request = new Request(url, { ...init, signal })
Expand Down

0 comments on commit b694310

Please sign in to comment.