@verdaccio/server 6.0.0-6-next.36 → 6.0.0-6-next.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +94 -0
- package/build/server.d.ts +0 -6
- package/build/server.js +19 -21
- package/build/server.js.map +1 -1
- package/package.json +15 -15
- package/src/server.ts +25 -45
- package/tsconfig.json +0 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,99 @@
|
|
|
1
1
|
# @verdaccio/server
|
|
2
2
|
|
|
3
|
+
## 6.0.0-6-next.38
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [ce013d2f]
|
|
8
|
+
- @verdaccio/api@6.0.0-6-next.32
|
|
9
|
+
- @verdaccio/store@6.0.0-6-next.29
|
|
10
|
+
- @verdaccio/web@6.0.0-6-next.36
|
|
11
|
+
- @verdaccio/core@6.0.0-6-next.49
|
|
12
|
+
- @verdaccio/config@6.0.0-6-next.49
|
|
13
|
+
- @verdaccio/auth@6.0.0-6-next.28
|
|
14
|
+
- @verdaccio/loaders@6.0.0-6-next.18
|
|
15
|
+
- @verdaccio/logger@6.0.0-6-next.17
|
|
16
|
+
- @verdaccio/middleware@6.0.0-6-next.28
|
|
17
|
+
- verdaccio-audit@11.0.0-6-next.12
|
|
18
|
+
- @verdaccio/utils@6.0.0-6-next.17
|
|
19
|
+
|
|
20
|
+
## 6.0.0-6-next.37
|
|
21
|
+
|
|
22
|
+
### Major Changes
|
|
23
|
+
|
|
24
|
+
- 9fc2e796: feat(plugins): improve plugin loader
|
|
25
|
+
|
|
26
|
+
### Changes
|
|
27
|
+
|
|
28
|
+
- Add scope plugin support to 6.x https://github.com/verdaccio/verdaccio/pull/3227
|
|
29
|
+
- Avoid config collisions https://github.com/verdaccio/verdaccio/issues/928
|
|
30
|
+
- https://github.com/verdaccio/verdaccio/issues/1394
|
|
31
|
+
- `config.plugins` plugin path validations
|
|
32
|
+
- Updated algorithm for plugin loader.
|
|
33
|
+
- improved documentation (included dev)
|
|
34
|
+
|
|
35
|
+
## Features
|
|
36
|
+
|
|
37
|
+
- Add scope plugin support to 6.x https://github.com/verdaccio/verdaccio/pull/3227
|
|
38
|
+
- Custom prefix:
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
// config.yaml
|
|
42
|
+
server:
|
|
43
|
+
pluginPrefix: mycompany
|
|
44
|
+
middleware:
|
|
45
|
+
audit:
|
|
46
|
+
foo: 1
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
This configuration will look up for `mycompany-audit` instead `Verdaccio-audit`.
|
|
50
|
+
|
|
51
|
+
## Breaking Changes
|
|
52
|
+
|
|
53
|
+
### sinopia plugins
|
|
54
|
+
|
|
55
|
+
- `sinopia` fallback support is removed, but can be restored using `pluginPrefix`
|
|
56
|
+
|
|
57
|
+
### plugin filter
|
|
58
|
+
|
|
59
|
+
- method rename `filter_metadata`->`filterMetadata`
|
|
60
|
+
|
|
61
|
+
### Plugin constructor does not merge configs anymore https://github.com/verdaccio/verdaccio/issues/928
|
|
62
|
+
|
|
63
|
+
The plugin receives as first argument `config`, which represents the config of the plugin. Example:
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
// config.yaml
|
|
67
|
+
auth:
|
|
68
|
+
plugin:
|
|
69
|
+
foo: 1
|
|
70
|
+
bar: 2
|
|
71
|
+
|
|
72
|
+
export class Plugin<T> {
|
|
73
|
+
public constructor(config: T, options: PluginOptions) {
|
|
74
|
+
console.log(config);
|
|
75
|
+
// {foo:1, bar: 2}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Patch Changes
|
|
81
|
+
|
|
82
|
+
- Updated dependencies [43f32687]
|
|
83
|
+
- Updated dependencies [9fc2e796]
|
|
84
|
+
- Updated dependencies [62c24b63]
|
|
85
|
+
- @verdaccio/api@6.0.0-6-next.31
|
|
86
|
+
- @verdaccio/core@6.0.0-6-next.48
|
|
87
|
+
- @verdaccio/store@6.0.0-6-next.28
|
|
88
|
+
- @verdaccio/auth@6.0.0-6-next.27
|
|
89
|
+
- @verdaccio/config@6.0.0-6-next.48
|
|
90
|
+
- @verdaccio/loaders@6.0.0-6-next.17
|
|
91
|
+
- verdaccio-audit@11.0.0-6-next.11
|
|
92
|
+
- @verdaccio/web@6.0.0-6-next.35
|
|
93
|
+
- @verdaccio/utils@6.0.0-6-next.16
|
|
94
|
+
- @verdaccio/logger@6.0.0-6-next.16
|
|
95
|
+
- @verdaccio/middleware@6.0.0-6-next.27
|
|
96
|
+
|
|
3
97
|
## 6.0.0-6-next.36
|
|
4
98
|
|
|
5
99
|
### Patch Changes
|
package/build/server.d.ts
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
import { IBasicAuth } from '@verdaccio/auth';
|
|
2
|
-
import { Storage } from '@verdaccio/store';
|
|
3
1
|
import { ConfigYaml } from '@verdaccio/types';
|
|
4
|
-
import { IPlugin } from '@verdaccio/types';
|
|
5
|
-
export interface IPluginMiddleware<T> extends IPlugin<T> {
|
|
6
|
-
register_middlewares(app: any, auth: IBasicAuth<T>, storage: Storage): void;
|
|
7
|
-
}
|
|
8
2
|
declare const _default: (configHash: ConfigYaml) => Promise<any>;
|
|
9
3
|
export default _default;
|
package/build/server.js
CHANGED
|
@@ -45,8 +45,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
45
45
|
|
|
46
46
|
const debug = (0, _debug.default)('verdaccio:server');
|
|
47
47
|
|
|
48
|
-
const defineAPI = function (config, storage) {
|
|
48
|
+
const defineAPI = async function (config, storage) {
|
|
49
49
|
const auth = new _auth.Auth(config);
|
|
50
|
+
await auth.init();
|
|
50
51
|
const app = (0, _express.default)();
|
|
51
52
|
const limiter = new _expressRateLimit.default(config.serverSettings.rateLimit); // run in production mode by default, just in case
|
|
52
53
|
// it shouldn't make any difference anyway
|
|
@@ -69,19 +70,20 @@ const defineAPI = function (config, storage) {
|
|
|
69
70
|
|
|
70
71
|
if (config._debug) {
|
|
71
72
|
(0, _debug2.default)(app, config.configPath);
|
|
72
|
-
}
|
|
73
|
-
|
|
73
|
+
}
|
|
74
74
|
|
|
75
|
-
const
|
|
76
|
-
config
|
|
75
|
+
const plugins = await (0, _loaders.asyncLoadPlugin)(config.middlewares, {
|
|
76
|
+
config,
|
|
77
77
|
logger: _logger.logger
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return plugin.register_middlewares;
|
|
78
|
+
}, function (plugin) {
|
|
79
|
+
return typeof plugin.register_middlewares !== 'undefined';
|
|
81
80
|
});
|
|
82
81
|
|
|
83
|
-
if (
|
|
84
|
-
|
|
82
|
+
if (plugins.length === 0) {
|
|
83
|
+
_logger.logger.info('none middleware plugins has been defined, adding audit middleware by default'); // @ts-ignore
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
plugins.push(new _verdaccioAudit.default({
|
|
85
87
|
enabled: true,
|
|
86
88
|
strict_ssl: true
|
|
87
89
|
}, {
|
|
@@ -98,7 +100,7 @@ const defineAPI = function (config, storage) {
|
|
|
98
100
|
app.use((0, _api.default)(config, auth, storage)); // For WebUI & WebUI API
|
|
99
101
|
|
|
100
102
|
if (_lodash.default.get(config, 'web.enable', true)) {
|
|
101
|
-
app.use((0, _web.default)(config, auth, storage));
|
|
103
|
+
app.use(await (0, _web.default)(config, auth, storage));
|
|
102
104
|
} else {
|
|
103
105
|
app.get('/', function (req, res, next) {
|
|
104
106
|
next(_core.errorUtils.getNotFound(_core.API_ERROR.WEB_DISABLED));
|
|
@@ -131,15 +133,11 @@ const defineAPI = function (config, storage) {
|
|
|
131
133
|
return app;
|
|
132
134
|
};
|
|
133
135
|
|
|
134
|
-
var
|
|
136
|
+
var startServer = async function startServer(configHash) {
|
|
135
137
|
debug('start server');
|
|
136
|
-
const config = new _config.Config(
|
|
138
|
+
const config = new _config.Config({ ...configHash
|
|
139
|
+
}); // register middleware plugins
|
|
137
140
|
|
|
138
|
-
const plugin_params = {
|
|
139
|
-
config: config,
|
|
140
|
-
logger: _logger.logger
|
|
141
|
-
};
|
|
142
|
-
const filters = (0, _loaders.loadPlugin)(config, config.filters || {}, plugin_params, plugin => plugin.filter_metadata);
|
|
143
141
|
debug('loaded filter plugin'); // @ts-ignore
|
|
144
142
|
|
|
145
143
|
const storage = new _store.Storage(config);
|
|
@@ -147,7 +145,7 @@ var _default = async function _default(configHash) {
|
|
|
147
145
|
try {
|
|
148
146
|
// waits until init calls have been initialized
|
|
149
147
|
debug('storage init start');
|
|
150
|
-
await storage.init(config
|
|
148
|
+
await storage.init(config);
|
|
151
149
|
debug('storage init end');
|
|
152
150
|
} catch (err) {
|
|
153
151
|
_logger.logger.error({
|
|
@@ -157,8 +155,8 @@ var _default = async function _default(configHash) {
|
|
|
157
155
|
throw new Error(err);
|
|
158
156
|
}
|
|
159
157
|
|
|
160
|
-
return defineAPI(config, storage);
|
|
158
|
+
return await defineAPI(config, storage);
|
|
161
159
|
};
|
|
162
160
|
|
|
163
|
-
exports.default =
|
|
161
|
+
exports.default = startServer;
|
|
164
162
|
//# sourceMappingURL=server.js.map
|
package/build/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","names":["debug","buildDebug","defineAPI","config","storage","auth","Auth","app","express","limiter","RateLimit","serverSettings","rateLimit","set","process","env","NODE_ENV","use","cors","log","errorReportingMiddleware","req","res","next","setHeader","getUserAgent","user_agent","compression","get","url","_debug","hookDebug","configPath","
|
|
1
|
+
{"version":3,"file":"server.js","names":["debug","buildDebug","defineAPI","config","storage","auth","Auth","init","app","express","limiter","RateLimit","serverSettings","rateLimit","set","process","env","NODE_ENV","use","cors","log","errorReportingMiddleware","req","res","next","setHeader","getUserAgent","user_agent","compression","get","url","_debug","hookDebug","configPath","plugins","asyncLoadPlugin","middlewares","logger","plugin","register_middlewares","length","info","push","AuditMiddleware","enabled","strict_ssl","forEach","apiEndpoint","_","webMiddleware","errorUtils","getNotFound","API_ERROR","WEB_DISABLED","err","isError","code","statusCode","HTTP_STATUS","NOT_MODIFIED","isFunction","locals","report_error","noop","final","startServer","configHash","AppConfig","Storage","error","msg","Error"],"sources":["../src/server.ts"],"sourcesContent":["import compression from 'compression';\nimport cors from 'cors';\nimport buildDebug from 'debug';\nimport express from 'express';\nimport RateLimit from 'express-rate-limit';\nimport { HttpError } from 'http-errors';\nimport _ from 'lodash';\nimport AuditMiddleware from 'verdaccio-audit';\n\nimport apiEndpoint from '@verdaccio/api';\nimport { Auth } from '@verdaccio/auth';\nimport { Config as AppConfig } from '@verdaccio/config';\nimport { API_ERROR, HTTP_STATUS, errorUtils, pluginUtils } from '@verdaccio/core';\nimport { asyncLoadPlugin } from '@verdaccio/loaders';\nimport { logger } from '@verdaccio/logger';\nimport { errorReportingMiddleware, final, log } from '@verdaccio/middleware';\nimport { Storage } from '@verdaccio/store';\nimport { ConfigYaml } from '@verdaccio/types';\nimport { Config as IConfig } from '@verdaccio/types';\nimport webMiddleware from '@verdaccio/web';\n\nimport { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types/custom';\nimport hookDebug from './debug';\nimport { getUserAgent } from './utils';\n\nconst debug = buildDebug('verdaccio:server');\n\nconst defineAPI = async function (config: IConfig, storage: Storage): Promise<any> {\n const auth: Auth = new Auth(config);\n await auth.init();\n const app = express();\n const limiter = new RateLimit(config.serverSettings.rateLimit);\n // run in production mode by default, just in case\n // it shouldn't make any difference anyway\n app.set('env', process.env.NODE_ENV || 'production');\n app.use(cors());\n app.use(limiter);\n\n // Router setup\n app.use(log);\n app.use(errorReportingMiddleware);\n app.use(function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {\n res.setHeader('x-powered-by', getUserAgent(config.user_agent));\n next();\n });\n\n app.use(compression());\n\n app.get(\n '/favicon.ico',\n function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {\n req.url = '/-/static/favicon.png';\n next();\n }\n );\n\n // Hook for tests only\n if (config._debug) {\n hookDebug(app, config.configPath);\n }\n\n const plugins: pluginUtils.ExpressMiddleware<IConfig, {}, Auth>[] = await asyncLoadPlugin(\n config.middlewares,\n {\n config,\n logger,\n },\n function (plugin) {\n return typeof plugin.register_middlewares !== 'undefined';\n }\n );\n\n if (plugins.length === 0) {\n logger.info('none middleware plugins has been defined, adding audit middleware by default');\n // @ts-ignore\n plugins.push(new AuditMiddleware({ enabled: true, strict_ssl: true }, { config, logger }));\n }\n\n plugins.forEach((plugin: pluginUtils.ExpressMiddleware<IConfig, {}, Auth>) => {\n plugin.register_middlewares(app, auth, storage);\n });\n\n // For npm request\n // @ts-ignore\n app.use(apiEndpoint(config, auth, storage));\n\n // For WebUI & WebUI API\n if (_.get(config, 'web.enable', true)) {\n app.use(await webMiddleware(config, auth, storage));\n } else {\n app.get('/', function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {\n next(errorUtils.getNotFound(API_ERROR.WEB_DISABLED));\n });\n }\n\n // Catch 404\n app.get('/*', function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {\n next(errorUtils.getNotFound('resource not found'));\n });\n\n app.use(function (\n err: HttpError,\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n ) {\n if (_.isError(err)) {\n if (err.code === 'ECONNABORT' && res.statusCode === HTTP_STATUS.NOT_MODIFIED) {\n return next();\n }\n if (_.isFunction(res.locals.report_error) === false) {\n // in case of very early error this middleware may not be loaded before error is generated\n // fixing that\n errorReportingMiddleware(req, res, _.noop);\n }\n res.locals.report_error(err);\n } else {\n // Fall to Middleware.final\n return next(err);\n }\n });\n\n app.use(final);\n\n return app;\n};\n\nexport default (async function startServer(configHash: ConfigYaml): Promise<any> {\n debug('start server');\n const config: IConfig = new AppConfig({ ...configHash } as any);\n // register middleware plugins\n debug('loaded filter plugin');\n // @ts-ignore\n const storage: Storage = new Storage(config);\n try {\n // waits until init calls have been initialized\n debug('storage init start');\n await storage.init(config);\n debug('storage init end');\n } catch (err: any) {\n logger.error({ error: err.msg }, 'storage has failed: @{error}');\n throw new Error(err);\n }\n return await defineAPI(config, storage);\n});\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAGA;;AAGA;;AACA;;;;AAEA,MAAMA,KAAK,GAAG,IAAAC,cAAA,EAAW,kBAAX,CAAd;;AAEA,MAAMC,SAAS,GAAG,gBAAgBC,MAAhB,EAAiCC,OAAjC,EAAiE;EACjF,MAAMC,IAAU,GAAG,IAAIC,UAAJ,CAASH,MAAT,CAAnB;EACA,MAAME,IAAI,CAACE,IAAL,EAAN;EACA,MAAMC,GAAG,GAAG,IAAAC,gBAAA,GAAZ;EACA,MAAMC,OAAO,GAAG,IAAIC,yBAAJ,CAAcR,MAAM,CAACS,cAAP,CAAsBC,SAApC,CAAhB,CAJiF,CAKjF;EACA;;EACAL,GAAG,CAACM,GAAJ,CAAQ,KAAR,EAAeC,OAAO,CAACC,GAAR,CAAYC,QAAZ,IAAwB,YAAvC;EACAT,GAAG,CAACU,GAAJ,CAAQ,IAAAC,aAAA,GAAR;EACAX,GAAG,CAACU,GAAJ,CAAQR,OAAR,EATiF,CAWjF;;EACAF,GAAG,CAACU,GAAJ,CAAQE,eAAR;EACAZ,GAAG,CAACU,GAAJ,CAAQG,oCAAR;EACAb,GAAG,CAACU,GAAJ,CAAQ,UAAUI,GAAV,EAA+BC,GAA/B,EAAqDC,IAArD,EAAmF;IACzFD,GAAG,CAACE,SAAJ,CAAc,cAAd,EAA8B,IAAAC,mBAAA,EAAavB,MAAM,CAACwB,UAApB,CAA9B;IACAH,IAAI;EACL,CAHD;EAKAhB,GAAG,CAACU,GAAJ,CAAQ,IAAAU,oBAAA,GAAR;EAEApB,GAAG,CAACqB,GAAJ,CACE,cADF,EAEE,UAAUP,GAAV,EAA+BC,GAA/B,EAAqDC,IAArD,EAAmF;IACjFF,GAAG,CAACQ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,CAAC,sBAAD,CAAL,CAJ+E,CAK/E;;EACA,MAAMI,OAAgB,GAAG,IAAIgE,cAAJ,CAAYjE,MAAZ,CAAzB;;EACA,IAAI;IACF;IACAH,KAAK,CAAC,oBAAD,CAAL;IACA,MAAMI,OAAO,CAACG,IAAR,CAAaJ,MAAb,CAAN;IACAH,KAAK,CAAC,kBAAD,CAAL;EACD,CALD,CAKE,OAAOsD,GAAP,EAAiB;IACjBjB,cAAA,CAAOgC,KAAP,CAAa;MAAEA,KAAK,EAAEf,GAAG,CAACgB;IAAb,CAAb,EAAiC,8BAAjC;;IACA,MAAM,IAAIC,KAAJ,CAAUjB,GAAV,CAAN;EACD;;EACD,OAAO,MAAMpD,SAAS,CAACC,MAAD,EAASC,OAAT,CAAtB;AACD,C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verdaccio/server",
|
|
3
|
-
"version": "6.0.0-6-next.
|
|
3
|
+
"version": "6.0.0-6-next.38",
|
|
4
4
|
"description": "server logic",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -30,17 +30,17 @@
|
|
|
30
30
|
"npm": ">=6"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@verdaccio/api": "6.0.0-6-next.
|
|
34
|
-
"@verdaccio/auth": "6.0.0-6-next.
|
|
35
|
-
"@verdaccio/core": "6.0.0-6-next.
|
|
36
|
-
"@verdaccio/config": "6.0.0-6-next.
|
|
37
|
-
"@verdaccio/loaders": "6.0.0-6-next.
|
|
38
|
-
"@verdaccio/logger": "6.0.0-6-next.
|
|
39
|
-
"@verdaccio/middleware": "6.0.0-6-next.
|
|
40
|
-
"@verdaccio/store": "6.0.0-6-next.
|
|
41
|
-
"@verdaccio/utils": "6.0.0-6-next.
|
|
42
|
-
"@verdaccio/web": "6.0.0-6-next.
|
|
43
|
-
"verdaccio-audit": "11.0.0-6-next.
|
|
33
|
+
"@verdaccio/api": "6.0.0-6-next.32",
|
|
34
|
+
"@verdaccio/auth": "6.0.0-6-next.28",
|
|
35
|
+
"@verdaccio/core": "6.0.0-6-next.49",
|
|
36
|
+
"@verdaccio/config": "6.0.0-6-next.49",
|
|
37
|
+
"@verdaccio/loaders": "6.0.0-6-next.18",
|
|
38
|
+
"@verdaccio/logger": "6.0.0-6-next.17",
|
|
39
|
+
"@verdaccio/middleware": "6.0.0-6-next.28",
|
|
40
|
+
"@verdaccio/store": "6.0.0-6-next.29",
|
|
41
|
+
"@verdaccio/utils": "6.0.0-6-next.17",
|
|
42
|
+
"@verdaccio/web": "6.0.0-6-next.36",
|
|
43
|
+
"verdaccio-audit": "11.0.0-6-next.12",
|
|
44
44
|
"compression": "1.7.4",
|
|
45
45
|
"cors": "2.8.5",
|
|
46
46
|
"debug": "4.3.4",
|
|
@@ -49,9 +49,9 @@
|
|
|
49
49
|
"lodash": "4.17.21"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@types/node": "16.11.
|
|
53
|
-
"@verdaccio/proxy": "6.0.0-6-next.
|
|
54
|
-
"@verdaccio/test-helper": "
|
|
52
|
+
"@types/node": "16.11.62",
|
|
53
|
+
"@verdaccio/proxy": "6.0.0-6-next.27",
|
|
54
|
+
"@verdaccio/test-helper": "2.0.0-6-next.6",
|
|
55
55
|
"http-errors": "1.8.1"
|
|
56
56
|
},
|
|
57
57
|
"funding": {
|
package/src/server.ts
CHANGED
|
@@ -1,37 +1,34 @@
|
|
|
1
1
|
import compression from 'compression';
|
|
2
2
|
import cors from 'cors';
|
|
3
3
|
import buildDebug from 'debug';
|
|
4
|
-
import express
|
|
4
|
+
import express from 'express';
|
|
5
5
|
import RateLimit from 'express-rate-limit';
|
|
6
6
|
import { HttpError } from 'http-errors';
|
|
7
7
|
import _ from 'lodash';
|
|
8
8
|
import AuditMiddleware from 'verdaccio-audit';
|
|
9
9
|
|
|
10
10
|
import apiEndpoint from '@verdaccio/api';
|
|
11
|
-
import { Auth
|
|
11
|
+
import { Auth } from '@verdaccio/auth';
|
|
12
12
|
import { Config as AppConfig } from '@verdaccio/config';
|
|
13
|
-
import { API_ERROR, HTTP_STATUS, errorUtils } from '@verdaccio/core';
|
|
14
|
-
import {
|
|
13
|
+
import { API_ERROR, HTTP_STATUS, errorUtils, pluginUtils } from '@verdaccio/core';
|
|
14
|
+
import { asyncLoadPlugin } from '@verdaccio/loaders';
|
|
15
15
|
import { logger } from '@verdaccio/logger';
|
|
16
16
|
import { errorReportingMiddleware, final, log } from '@verdaccio/middleware';
|
|
17
17
|
import { Storage } from '@verdaccio/store';
|
|
18
18
|
import { ConfigYaml } from '@verdaccio/types';
|
|
19
|
-
import { Config as IConfig
|
|
19
|
+
import { Config as IConfig } from '@verdaccio/types';
|
|
20
20
|
import webMiddleware from '@verdaccio/web';
|
|
21
21
|
|
|
22
22
|
import { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types/custom';
|
|
23
23
|
import hookDebug from './debug';
|
|
24
24
|
import { getUserAgent } from './utils';
|
|
25
25
|
|
|
26
|
-
export interface IPluginMiddleware<T> extends IPlugin<T> {
|
|
27
|
-
register_middlewares(app: any, auth: IBasicAuth<T>, storage: Storage): void;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
26
|
const debug = buildDebug('verdaccio:server');
|
|
31
27
|
|
|
32
|
-
const defineAPI = function (config: IConfig, storage: Storage): any {
|
|
28
|
+
const defineAPI = async function (config: IConfig, storage: Storage): Promise<any> {
|
|
33
29
|
const auth: Auth = new Auth(config);
|
|
34
|
-
|
|
30
|
+
await auth.init();
|
|
31
|
+
const app = express();
|
|
35
32
|
const limiter = new RateLimit(config.serverSettings.rateLimit);
|
|
36
33
|
// run in production mode by default, just in case
|
|
37
34
|
// it shouldn't make any difference anyway
|
|
@@ -62,31 +59,24 @@ const defineAPI = function (config: IConfig, storage: Storage): any {
|
|
|
62
59
|
hookDebug(app, config.configPath);
|
|
63
60
|
}
|
|
64
61
|
|
|
65
|
-
|
|
66
|
-
const plugin_params = {
|
|
67
|
-
config: config,
|
|
68
|
-
logger: logger,
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const plugins: IPluginMiddleware<IConfig>[] = loadPlugin(
|
|
72
|
-
config,
|
|
62
|
+
const plugins: pluginUtils.ExpressMiddleware<IConfig, {}, Auth>[] = await asyncLoadPlugin(
|
|
73
63
|
config.middlewares,
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
64
|
+
{
|
|
65
|
+
config,
|
|
66
|
+
logger,
|
|
67
|
+
},
|
|
68
|
+
function (plugin) {
|
|
69
|
+
return typeof plugin.register_middlewares !== 'undefined';
|
|
77
70
|
}
|
|
78
71
|
);
|
|
79
72
|
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
{ config, logger: logger }
|
|
85
|
-
)
|
|
86
|
-
);
|
|
73
|
+
if (plugins.length === 0) {
|
|
74
|
+
logger.info('none middleware plugins has been defined, adding audit middleware by default');
|
|
75
|
+
// @ts-ignore
|
|
76
|
+
plugins.push(new AuditMiddleware({ enabled: true, strict_ssl: true }, { config, logger }));
|
|
87
77
|
}
|
|
88
78
|
|
|
89
|
-
plugins.forEach((plugin:
|
|
79
|
+
plugins.forEach((plugin: pluginUtils.ExpressMiddleware<IConfig, {}, Auth>) => {
|
|
90
80
|
plugin.register_middlewares(app, auth, storage);
|
|
91
81
|
});
|
|
92
82
|
|
|
@@ -96,7 +86,7 @@ const defineAPI = function (config: IConfig, storage: Storage): any {
|
|
|
96
86
|
|
|
97
87
|
// For WebUI & WebUI API
|
|
98
88
|
if (_.get(config, 'web.enable', true)) {
|
|
99
|
-
app.use(webMiddleware(config, auth, storage));
|
|
89
|
+
app.use(await webMiddleware(config, auth, storage));
|
|
100
90
|
} else {
|
|
101
91
|
app.get('/', function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {
|
|
102
92
|
next(errorUtils.getNotFound(API_ERROR.WEB_DISABLED));
|
|
@@ -135,31 +125,21 @@ const defineAPI = function (config: IConfig, storage: Storage): any {
|
|
|
135
125
|
return app;
|
|
136
126
|
};
|
|
137
127
|
|
|
138
|
-
export default (async function (configHash: ConfigYaml): Promise<any> {
|
|
128
|
+
export default (async function startServer(configHash: ConfigYaml): Promise<any> {
|
|
139
129
|
debug('start server');
|
|
140
|
-
const config: IConfig = new AppConfig(
|
|
130
|
+
const config: IConfig = new AppConfig({ ...configHash } as any);
|
|
141
131
|
// register middleware plugins
|
|
142
|
-
const plugin_params = {
|
|
143
|
-
config: config,
|
|
144
|
-
logger,
|
|
145
|
-
};
|
|
146
|
-
const filters = loadPlugin(
|
|
147
|
-
config,
|
|
148
|
-
config.filters || {},
|
|
149
|
-
plugin_params,
|
|
150
|
-
(plugin: IPluginStorageFilter<IConfig>) => plugin.filter_metadata
|
|
151
|
-
);
|
|
152
132
|
debug('loaded filter plugin');
|
|
153
133
|
// @ts-ignore
|
|
154
134
|
const storage: Storage = new Storage(config);
|
|
155
135
|
try {
|
|
156
136
|
// waits until init calls have been initialized
|
|
157
137
|
debug('storage init start');
|
|
158
|
-
await storage.init(config
|
|
138
|
+
await storage.init(config);
|
|
159
139
|
debug('storage init end');
|
|
160
140
|
} catch (err: any) {
|
|
161
141
|
logger.error({ error: err.msg }, 'storage has failed: @{error}');
|
|
162
142
|
throw new Error(err);
|
|
163
143
|
}
|
|
164
|
-
return defineAPI(config, storage);
|
|
144
|
+
return await defineAPI(config, storage);
|
|
165
145
|
});
|
package/tsconfig.json
CHANGED
|
@@ -16,9 +16,6 @@
|
|
|
16
16
|
{
|
|
17
17
|
"path": "../../config"
|
|
18
18
|
},
|
|
19
|
-
{
|
|
20
|
-
"path": "../../core/commons-api"
|
|
21
|
-
},
|
|
22
19
|
{
|
|
23
20
|
"path": "../../loaders"
|
|
24
21
|
},
|
|
@@ -28,9 +25,6 @@
|
|
|
28
25
|
{
|
|
29
26
|
"path": "../../middleware"
|
|
30
27
|
},
|
|
31
|
-
{
|
|
32
|
-
"path": "../../mock"
|
|
33
|
-
},
|
|
34
28
|
{
|
|
35
29
|
"path": "../../plugins/audit"
|
|
36
30
|
},
|