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

feat: verdaccio-audit support timeout option

This commit is contained in:
Leo Wang(草鞋没号) 2024-07-17 18:54:12 +08:00
parent 2a6ee33071
commit ed008438ec
2 changed files with 11 additions and 1 deletions

View file

@ -19,11 +19,13 @@ export default class ProxyAudit
public enabled: boolean;
public logger: Logger;
public strict_ssl: boolean;
public timeout: number;
public constructor(config: ConfigAudit, options: pluginUtils.PluginOptions) {
super(config, options);
this.enabled = config.enabled || false;
this.strict_ssl = config.strict_ssl !== undefined ? config.strict_ssl : true;
this.timeout = config.timeout ?? 1000 * 60 * 1;
this.logger = options.logger;
}
@ -57,7 +59,14 @@ export default class ProxyAudit
const auditEndpoint = `${REGISTRY_DOMAIN}${req.baseUrl}${req.route.path}`;
this.logger.debug('fetching audit from ' + auditEndpoint);
const response = await fetch(auditEndpoint, requestOptions);
const controller = new AbortController();
setTimeout(() => controller.abort(`Fetch ${auditEndpoint} timeout ${this.timeout}ms`), this.timeout);
const response = await fetch(auditEndpoint, {
...requestOptions,
signal: controller.signal,
});
if (response.ok) {
res.status(response.status).send(await response.json());

View file

@ -2,4 +2,5 @@ export interface ConfigAudit {
enabled: boolean;
max_body?: string;
strict_ssl?: boolean;
timeout?: number;
}