Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/api/contributors.get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default defineCachedEventHandler(
{
headers: {
'Accept': 'application/vnd.github.v3+json',
'User-Agent': 'npmx.dev',
'User-Agent': 'npmx',
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

every other user-agent is npmx not npmx.dev

},
},
)
Expand Down
33 changes: 15 additions & 18 deletions server/utils/docs/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ function createLoader(): (
let url: URL
try {
url = new URL(specifier)
} catch {
} catch (e) {
// eslint-disable-next-line no-console
console.error(e)
return undefined
}

Expand All @@ -93,21 +95,18 @@ function createLoader(): (
return undefined
}

const controller = new AbortController()
const timeoutId = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS)

try {
const response = await fetch(url.toString(), {
const response = await $fetch.raw<Blob>(url.toString(), {
method: 'GET',
timeout: FETCH_TIMEOUT_MS,
redirect: 'follow',
signal: controller.signal,
})
clearTimeout(timeoutId)

if (response.status !== 200) {
return undefined
}

const content = await response.text()
const content = (await response._data?.text()) ?? ''
const headers: Record<string, string> = {}
for (const [key, value] of response.headers) {
headers[key.toLowerCase()] = value
Expand All @@ -119,8 +118,9 @@ function createLoader(): (
headers,
content,
}
} catch {
clearTimeout(timeoutId)
} catch (e) {
// eslint-disable-next-line no-console
console.error(e)
return undefined
}
}
Expand Down Expand Up @@ -161,18 +161,15 @@ function createResolver(): (specifier: string, referrer: string) => string {
async function getTypesUrl(packageName: string, version: string): Promise<string | null> {
const url = `https://esm.sh/${packageName}@${version}`

const controller = new AbortController()
const timeoutId = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS)

try {
const response = await fetch(url, {
const response = await $fetch.raw(url, {
method: 'HEAD',
signal: controller.signal,
timeout: FETCH_TIMEOUT_MS,
})
clearTimeout(timeoutId)
return response.headers.get('x-typescript-types')
} catch {
clearTimeout(timeoutId)
} catch (e) {
// eslint-disable-next-line no-console
console.error(e)
return null
}
}
Loading