0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-30 22:34:10 -05:00

feat: trustProxy property (#3691)

This commit is contained in:
Juan Picado 2023-03-18 21:54:09 +01:00 committed by GitHub
parent 6ffb0091bd
commit 16e38df8ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 36 additions and 7 deletions

View file

@ -0,0 +1,9 @@
---
'@verdaccio/config': minor
'@verdaccio/core': minor
'@verdaccio/types': minor
'@verdaccio/server': minor
'@verdaccio/store': minor
---
feat: trustProxy property

View file

@ -106,6 +106,9 @@ server:
# A regex for the password validation /.{3}$/ (3 characters min) # A regex for the password validation /.{3}$/ (3 characters min)
# An example to limit to 10 characters minimum # An example to limit to 10 characters minimum
# passwordValidationRegex: /.{10}$/ # passwordValidationRegex: /.{10}$/
# Allow `req.ip` to resolve properly when Verdaccio is behind a proxy or load-balancer
# See: https://expressjs.com/en/guide/behind-proxies.html
# trustProxy: '127.0.0.1'
# https://verdaccio.org/docs/configuration#offline-publish # https://verdaccio.org/docs/configuration#offline-publish
# publish: # publish:

View file

@ -112,6 +112,9 @@ server:
# A regex for the password validation /.{3}$/ (3 characters min) # A regex for the password validation /.{3}$/ (3 characters min)
# An example to limit to 10 characters minimum # An example to limit to 10 characters minimum
# passwordValidationRegex: /.{10}$/ # passwordValidationRegex: /.{10}$/
# Allow `req.ip` to resolve properly when Verdaccio is behind a proxy or load-balancer
# See: https://expressjs.com/en/guide/behind-proxies.html
# trustProxy: '127.0.0.1'
# https://verdaccio.org/docs/configuration#offline-publish # https://verdaccio.org/docs/configuration#offline-publish
# publish: # publish:

View file

@ -170,5 +170,5 @@ export interface IBasicAuth {
} }
export interface ManifestFilter<T> extends Plugin<T> { export interface ManifestFilter<T> extends Plugin<T> {
filterMetadata(packageInfo: Manifest): Promise<Manifest>; filter_metadata(packageInfo: Manifest): Promise<Manifest>;
} }

View file

@ -30,14 +30,14 @@
"publishConfig": { "publishConfig": {
"access": "public" "access": "public"
}, },
"main": "build/types.d.ts", "main": "src/types.ts",
"types": "build/types.d.ts", "types": "src/types.ts",
"scripts": { "scripts": {
"clean": "rimraf ./build", "clean": "rimraf ./build",
"test": "pnpm type-check", "test": "pnpm type-check",
"build:docs": "typedoc --options ./typedoc.json --tsconfig tsconfig.build.json", "build:docs": "typedoc --options ./typedoc.json --tsconfig tsconfig.build.json",
"type-check": "tsc --noEmit -p tsconfig.build.json", "type-check": "tsc --noEmit -p tsconfig.build.json",
"build": "tsc --emitDeclarationOnly -p tsconfig.build.json" "build": "echo 0"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "16.18.10", "@types/node": "16.18.10",

View file

@ -226,6 +226,8 @@ export type ServerSettingsConf = {
*/ */
pluginPrefix?: string; pluginPrefix?: string;
passwordValidationRegex?: RegExp; passwordValidationRegex?: RegExp;
// docs on `trustProxy` can be found at: https://expressjs.com/en/guide/behind-proxies.html
trustProxy?: string;
}; };
/** /**

View file

@ -89,6 +89,12 @@ export interface Tags {
[key: string]: Version; [key: string]: Version;
} }
export interface PeerDependenciesMeta {
[dependencyName: string]: {
optional?: boolean;
};
}
export interface Version { export interface Version {
name: string; name: string;
version: string; version: string;
@ -116,6 +122,7 @@ export interface Version {
peerDependencies?: Dependencies; peerDependencies?: Dependencies;
devDependencies?: Dependencies; devDependencies?: Dependencies;
optionalDependencies?: Dependencies; optionalDependencies?: Dependencies;
peerDependenciesMeta?: PeerDependenciesMeta;
bundleDependencies?: Dependencies; bundleDependencies?: Dependencies;
keywords?: string | string[]; keywords?: string | string[];
nodeVersion?: string; nodeVersion?: string;
@ -127,6 +134,8 @@ export interface Version {
funding?: { type: string; url: string }; funding?: { type: string; url: string };
engines?: Engines; engines?: Engines;
hasInstallScript?: boolean; hasInstallScript?: boolean;
cpu?: string[];
os?: string[];
} }
export interface Dependencies { export interface Dependencies {

View file

@ -31,6 +31,9 @@ const defineAPI = async function (config: IConfig, storage: Storage): Promise<an
// run in production mode by default, just in case // run in production mode by default, just in case
// it shouldn't make any difference anyway // it shouldn't make any difference anyway
app.set('env', process.env.NODE_ENV || 'production'); app.set('env', process.env.NODE_ENV || 'production');
if (config.server?.trustProxy) {
app.set('trust proxy', config.server.trustProxy);
}
app.use(cors()); app.use(cors());
app.use(rateLimit(config.serverSettings.rateLimit)); app.use(rateLimit(config.serverSettings.rateLimit));

View file

@ -670,8 +670,8 @@ class Storage {
config: this.config, config: this.config,
logger: this.logger, logger: this.logger,
}, },
(plugin) => { (plugin: pluginUtils.ManifestFilter<Config>) => {
return typeof plugin.filterMetadata !== 'undefined'; return typeof plugin.filter_metadata !== 'undefined';
}, },
this.config?.serverSettings?.pluginPrefix this.config?.serverSettings?.pluginPrefix
); );
@ -1786,7 +1786,7 @@ class Storage {
// and return it directly for // and return it directly for
// performance (i.e. need not be pure) // performance (i.e. need not be pure)
try { try {
filteredManifest = await filter.filterMetadata(manifest); filteredManifest = await filter.filter_metadata(manifest);
} catch (err: any) { } catch (err: any) {
this.logger.error({ err: err.message }, 'filter has failed @{err}'); this.logger.error({ err: err.message }, 'filter has failed @{err}');
filterPluginErrors.push(err); filterPluginErrors.push(err);