Skip to content

Commit

Permalink
Merge pull request #742 from podverse/develop
Browse files Browse the repository at this point in the history
Release v4.16.11
  • Loading branch information
mitchdowney authored Apr 19, 2024
2 parents f9bbcad + 825d1f4 commit f8f9556
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 26 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "podverse-api",
"version": "4.16.10",
"version": "4.16.11",
"description": "Data API, database migration scripts, and backend services for all Podverse models.",
"contributors": [
"Mitch Downey"
Expand Down
59 changes: 34 additions & 25 deletions src/lib/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,46 @@ export const request = async (url: string, options?: any) => {
}

export const getFinalRedirectedUrl = (url: string) => {
return new Promise<string>((resolve) => {
console.log('getFinalRedirectedUrl', url)
return new Promise<string>((resolve, reject) => {
const parsedOrginalUrl = new URL(url)
if (url.startsWith('https://')) {
const frRequest = https.request(
{
method: 'HEAD',
hostname: parsedOrginalUrl.hostname,
path: parsedOrginalUrl.pathname + parsedOrginalUrl.search,
Headers: {
'User-Agent': userAgent
const frRequest = https
.request(
{
method: 'HEAD',
hostname: parsedOrginalUrl.hostname,
path: parsedOrginalUrl.pathname + parsedOrginalUrl.search,
Headers: {
'User-Agent': userAgent
}
},
(response) => {
resolve(response.responseUrl)
}
},
(response) => {
resolve(response.responseUrl)
}
)
)
.on('error', (err) => {
reject(err)
})
frRequest.end()
} else {
const frRequest = http.request(
{
method: 'HEAD',
hostname: parsedOrginalUrl.hostname,
path: parsedOrginalUrl.pathname + parsedOrginalUrl.search,
Headers: {
'User-Agent': userAgent
const frRequest = http
.request(
{
method: 'HEAD',
hostname: parsedOrginalUrl.hostname,
path: parsedOrginalUrl.pathname + parsedOrginalUrl.search,
Headers: {
'User-Agent': userAgent
}
},
(response) => {
resolve(response.responseUrl)
}
},
(response) => {
resolve(response.responseUrl)
}
)
)
.on('error', (err) => {
reject(err)
})
frRequest.end()
}
})
Expand Down

0 comments on commit f8f9556

Please sign in to comment.