mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-30 22:34:10 -05:00
feat: verdaccio-audit support timeout option
This commit is contained in:
parent
2a6ee33071
commit
ed008438ec
2 changed files with 11 additions and 1 deletions
|
@ -19,11 +19,13 @@ export default class ProxyAudit
|
||||||
public enabled: boolean;
|
public enabled: boolean;
|
||||||
public logger: Logger;
|
public logger: Logger;
|
||||||
public strict_ssl: boolean;
|
public strict_ssl: boolean;
|
||||||
|
public timeout: number;
|
||||||
|
|
||||||
public constructor(config: ConfigAudit, options: pluginUtils.PluginOptions) {
|
public constructor(config: ConfigAudit, options: pluginUtils.PluginOptions) {
|
||||||
super(config, options);
|
super(config, options);
|
||||||
this.enabled = config.enabled || false;
|
this.enabled = config.enabled || false;
|
||||||
this.strict_ssl = config.strict_ssl !== undefined ? config.strict_ssl : true;
|
this.strict_ssl = config.strict_ssl !== undefined ? config.strict_ssl : true;
|
||||||
|
this.timeout = config.timeout ?? 1000 * 60 * 1;
|
||||||
this.logger = options.logger;
|
this.logger = options.logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +59,14 @@ export default class ProxyAudit
|
||||||
const auditEndpoint = `${REGISTRY_DOMAIN}${req.baseUrl}${req.route.path}`;
|
const auditEndpoint = `${REGISTRY_DOMAIN}${req.baseUrl}${req.route.path}`;
|
||||||
this.logger.debug('fetching audit from ' + auditEndpoint);
|
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) {
|
if (response.ok) {
|
||||||
res.status(response.status).send(await response.json());
|
res.status(response.status).send(await response.json());
|
||||||
|
|
|
@ -2,4 +2,5 @@ export interface ConfigAudit {
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
max_body?: string;
|
max_body?: string;
|
||||||
strict_ssl?: boolean;
|
strict_ssl?: boolean;
|
||||||
|
timeout?: number;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue