Skip to content
Draft
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
23 changes: 0 additions & 23 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion src/commands/base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ export default class BaseCommand extends Command {
httpProxy: flags.httpProxy,
certificateFile: flags.httpProxyCertificateFilename,
})
const apiOpts = { ...apiUrlOpts, agent }
const apiOpts = { ...apiUrlOpts, fetchOptions: { agent } }
const api = new NetlifyAPI(token ?? '', apiOpts)

actionCommand.siteId = flags.siteId || (typeof flags.site === 'string' && flags.site) || state.get('siteId')
Expand Down
63 changes: 22 additions & 41 deletions src/lib/http-agent.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,11 @@
import { readFile } from 'fs/promises'
import http from 'http'

Check failure on line 2 in src/lib/http-agent.ts

View workflow job for this annotation

GitHub Actions / Lint

'http' is defined but never used. Allowed unused vars must match /^_/u

import { HttpsProxyAgent } from 'https-proxy-agent'
import { HttpsProxyAgent, type HttpsProxyAgentOptions } from 'https-proxy-agent'

Check failure on line 4 in src/lib/http-agent.ts

View workflow job for this annotation

GitHub Actions / Lint

'HttpsProxyAgentOptions' is defined but never used. Allowed unused vars must match /^_/u

import { NETLIFYDEVERR, NETLIFYDEVWARN, exit, log } from '../utils/command-helpers.js'
import { waitPort } from './wait-port.js'

// https://github.com/TooTallNate/node-https-proxy-agent/issues/89
// Maybe replace with https://github.com/delvedor/hpagent
// @ts-expect-error TS(2507) FIXME: Type 'typeof createHttpsProxyAgent' is not a const... Remove this comment to see the full error message
class HttpsProxyAgentWithCA extends HttpsProxyAgent {
// @ts-expect-error TS(7006) FIXME: Parameter 'opts' implicitly has an 'any' type.
constructor(opts) {
super(opts)
// @ts-expect-error TS(2339) FIXME: Property 'ca' does not exist on type 'HttpsProxyAg... Remove this comment to see the full error message
this.ca = opts.ca
}

// @ts-expect-error TS(7006) FIXME: Parameter 'req' implicitly has an 'any' type.
callback(req, opts) {
return super.callback(req, {
...opts,
// @ts-expect-error TS(2339) FIXME: Property 'ca' does not exist on type 'HttpsProxyAg... Remove this comment to see the full error message
...(this.ca && { ca: this.ca }),
})
}
}

const DEFAULT_HTTP_PORT = 80
const DEFAULT_HTTPS_PORT = 443
// 50 seconds
Expand All @@ -44,7 +24,7 @@
message?: string | undefined
}
| {
agent: HttpsProxyAgentWithCA
agent: HttpsProxyAgent<string>
response: unknown
}
> => {
Expand Down Expand Up @@ -94,29 +74,30 @@
}
}

const opts = {
port: proxyUrl.port,
host: proxyUrl.host,
hostname: proxyUrl.hostname,
protocol: proxyUrl.protocol,
ca: certificate,
}

const agent = new HttpsProxyAgentWithCA(opts)
const agent = new HttpsProxyAgent(httpProxy, { ca: certificate })
response = { ...response, agent }
return response
}

// @ts-expect-error TS(7031) FIXME: Binding element 'certificateFile' implicitly has a... Remove this comment to see the full error message
export const getAgent = async ({ certificateFile, httpProxy }) => {
// @ts-expect-error TS(2339) FIXME: Property 'agent' does not exist on type '{ error?:... Remove this comment to see the full error message
const { agent, error, message, warning } = await tryGetAgent({ httpProxy, certificateFile })
if (error) {
log(NETLIFYDEVERR, error, message || '')
export const getAgent = async ({
certificateFile,
httpProxy,
}: {
certificateFile?: string
httpProxy?: string
}): Promise<HttpsProxyAgent<string> | undefined> => {
const result = await tryGetAgent({ httpProxy, certificateFile })

if ('error' in result && result.error) {
log(NETLIFYDEVERR, result.error, result.message || '')
exit(1)
}
if (warning) {
log(NETLIFYDEVWARN, warning, message || '')

if ('warning' in result && result.warning) {
log(NETLIFYDEVWARN, result.warning, result.message || '')
}

if ('agent' in result) {
return result.agent
}
return agent
}
Loading