Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: resolve CDN URLs #56

Merged
merged 1 commit into from
Feb 10, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ const reachableUrl = async (url, opts) => {

const isReachable = ({ statusCode }) => statusCode >= 200 && statusCode < 400

module.exports = async (url, opts) => reachableUrl(new URL(url).href, opts)
module.exports = async (url, opts) => {
if (/^\/\//.test(url)) url = `https:${url}`
return reachableUrl(new URL(url).href, opts)
}

module.exports.isReachable = isReachable
6 changes: 6 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ test('resolve url redirections', async t => {
t.is(res.url, 'https://microlink.io/?ref=produchunt')
})

test('resolve CDN url', async t => {
const url = '//yastatic.net/iconostasis/_/wT9gfGZZ80sP0VsoR6dgDyXJf2Y.png'
const res = await reachableUrl(url)
t.is(res.url, 'https://yastatic.net/iconostasis/_/wT9gfGZZ80sP0VsoR6dgDyXJf2Y.png')
})

test('fast unreachable request resolution', async t => {
t.timeout(1000)
const url = 'https://httpbin.org/status/404'
Expand Down