1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-11-08 23:25:51 +01:00

feat: verdaccio-audit support timeout option (#4718)

* feat: verdaccio-audit support timeout option

* Create many-bees-tickle.md

* Update audit.ts

* update docs

* Update README.md

---------

Co-authored-by: Juan Picado <juanpicado19@gmail.com>
This commit is contained in:
Leo Wang(草鞋没号) 2024-07-18 03:59:36 +08:00 committed by GitHub
parent c31aec8336
commit 136e992bb9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 24 additions and 1 deletions

@ -0,0 +1,5 @@
---
'verdaccio-audit': minor
---
feat: verdaccio-audit support timeout option

@ -187,6 +187,7 @@ server:
middlewares:
audit:
enabled: true
# timeout: 10000
# https://verdaccio.org/docs/logger
# log settings

@ -193,6 +193,7 @@ server:
middlewares:
audit:
enabled: true
# timeout: 10000
# https://verdaccio.org/docs/logger
# log settings

@ -26,6 +26,7 @@ middlewares:
audit:
enabled: true
strict_ssl: true # optional, defaults to true
timeout: 1000
```
### Strict SSL

@ -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,17 @@ 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());

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

@ -364,6 +364,7 @@ a built-in middleware plugin to handle this command.
middlewares:
audit:
enabled: true
# timeout: 10000
```
### Experiments {#experiments}

@ -387,6 +387,7 @@ a built-in middleware plugin to handle this command.
middlewares:
audit:
enabled: true
# timeout: 10000
```
### Experiments {#experiments}