Skip to content

Commit

Permalink
only set NODE_TLS_REJECT_UNAUTHORIZED after local request fails
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Nov 26, 2024
1 parent c9fa8b2 commit 6524a21
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,6 @@ async function updateReference(lang:string, target:string) {
qs += key + "=" + encodeURIComponent(options[key])
}
var typesUrl = combinePaths(baseUrl, "/types/" + lang) + qs
if (isUrlLocal(typesUrl)) {
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = "0"
}

await saveReference(lang, typesUrl, target)
}
Expand All @@ -268,7 +265,16 @@ async function saveReference(lang:string, typesUrl:string, fileName:string) {
console.log('saveReference', lang, typesUrl, fileName)
var filePath = path.resolve(fileName)
try {
const r = await fetch(typesUrl)
let r = null
try {
r = await fetch(typesUrl)
} catch (e) {
if (isUrlLocal(typesUrl)) {
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = "0"
r = await fetch(typesUrl)
}
else throw e
}
const dtos = await r.text()
try {
if (dtos.indexOf("Options:") === -1)
Expand Down

0 comments on commit 6524a21

Please sign in to comment.