0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-16 21:56:25 -05:00

chore: move agent_options to config (#4942)

* chore: move agent_options to config

* changeset
This commit is contained in:
Marc Bernard 2024-11-16 06:48:21 -05:00 committed by GitHub
parent 35360c8bbe
commit e308fbbf3a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 19 additions and 12 deletions

View file

@ -0,0 +1,6 @@
---
'@verdaccio/types': patch
'@verdaccio/proxy': patch
---
chore: move agent_options to config

View file

@ -1,3 +1,6 @@
import { AgentOptions as HttpAgentOptions } from 'node:http';
import { AgentOptions as HttpsAgentOptions } from 'node:https';
import { PackageAccess, PackageList } from '@verdaccio/types/src/manifest'; import { PackageAccess, PackageList } from '@verdaccio/types/src/manifest';
export type TypeToken = 'Bearer' | 'Basic'; export type TypeToken = 'Bearer' | 'Basic';
@ -47,6 +50,8 @@ export interface Headers {
[key: string]: string; [key: string]: string;
} }
export type AgentOptionsConf = HttpAgentOptions | HttpsAgentOptions;
export interface UpLinkTokenConf { export interface UpLinkTokenConf {
type: TypeToken; type: TypeToken;
token?: string; token?: string;
@ -64,6 +69,7 @@ export interface UpLinkConf {
headers?: Headers; headers?: Headers;
auth?: UpLinkTokenConf; auth?: UpLinkTokenConf;
strict_ssl?: boolean | void; strict_ssl?: boolean | void;
agent_options?: AgentOptionsConf;
_autogenerated?: boolean; _autogenerated?: boolean;
} }

View file

@ -1,21 +1,17 @@
import { Agents } from 'got-cjs'; import { Agents } from 'got-cjs';
import { HttpProxyAgent, HttpsProxyAgent } from 'hpagent'; import { HttpProxyAgent, HttpsProxyAgent } from 'hpagent';
import { Agent as HttpAgent, AgentOptions as HttpAgentOptions } from 'http'; import { Agent as HttpAgent } from 'http';
import { Agent as HttpsAgent, AgentOptions as HttpsAgentOptions } from 'https'; import { Agent as HttpsAgent } from 'https';
import { URL } from 'url'; import { URL } from 'url';
export type AgentOptionsConf = HttpAgentOptions | HttpsAgentOptions; import { AgentOptionsConf } from '@verdaccio/types';
class CustomAgents { class CustomAgents {
private url: string; private url: string;
private proxy: string | undefined; private proxy: string | undefined;
private agentOptions: HttpAgentOptions | HttpsAgentOptions; private agentOptions: AgentOptionsConf;
private agent: Agents; private agent: Agents;
public constructor( public constructor(url: string, proxy: string | undefined, agentOptions: AgentOptionsConf) {
url: string,
proxy: string | undefined,
agentOptions: HttpAgentOptions | HttpsAgentOptions
) {
this.proxy = proxy; this.proxy = proxy;
this.url = url; this.url = url;
this.agentOptions = agentOptions; this.agentOptions = agentOptions;

View file

@ -22,11 +22,10 @@ import {
errorUtils, errorUtils,
searchUtils, searchUtils,
} from '@verdaccio/core'; } from '@verdaccio/core';
import { Manifest } from '@verdaccio/types'; import { AgentOptionsConf, Config, Logger, Manifest, UpLinkConf } from '@verdaccio/types';
import { Config, Logger, UpLinkConf } from '@verdaccio/types';
import { buildToken } from '@verdaccio/utils'; import { buildToken } from '@verdaccio/utils';
import CustomAgents, { AgentOptionsConf } from './agent'; import CustomAgents from './agent';
import { parseInterval } from './proxy-utils'; import { parseInterval } from './proxy-utils';
const debug = buildDebug('verdaccio:proxy'); const debug = buildDebug('verdaccio:proxy');