@verdaccio/server 6.0.0-6-next.36 → 6.0.0-6-next.37
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 +77 -0
- package/build/server.js +16 -19
- package/build/server.js.map +1 -1
- package/package.json +15 -15
- package/src/server.ts +17 -32
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,82 @@
|
|
|
1
1
|
# @verdaccio/server
|
|
2
2
|
|
|
3
|
+
## 6.0.0-6-next.37
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 9fc2e796: feat(plugins): improve plugin loader
|
|
8
|
+
|
|
9
|
+
### Changes
|
|
10
|
+
|
|
11
|
+
- Add scope plugin support to 6.x https://github.com/verdaccio/verdaccio/pull/3227
|
|
12
|
+
- Avoid config collisions https://github.com/verdaccio/verdaccio/issues/928
|
|
13
|
+
- https://github.com/verdaccio/verdaccio/issues/1394
|
|
14
|
+
- `config.plugins` plugin path validations
|
|
15
|
+
- Updated algorithm for plugin loader.
|
|
16
|
+
- improved documentation (included dev)
|
|
17
|
+
|
|
18
|
+
## Features
|
|
19
|
+
|
|
20
|
+
- Add scope plugin support to 6.x https://github.com/verdaccio/verdaccio/pull/3227
|
|
21
|
+
- Custom prefix:
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
// config.yaml
|
|
25
|
+
server:
|
|
26
|
+
pluginPrefix: mycompany
|
|
27
|
+
middleware:
|
|
28
|
+
audit:
|
|
29
|
+
foo: 1
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
This configuration will look up for `mycompany-audit` instead `Verdaccio-audit`.
|
|
33
|
+
|
|
34
|
+
## Breaking Changes
|
|
35
|
+
|
|
36
|
+
### sinopia plugins
|
|
37
|
+
|
|
38
|
+
- `sinopia` fallback support is removed, but can be restored using `pluginPrefix`
|
|
39
|
+
|
|
40
|
+
### plugin filter
|
|
41
|
+
|
|
42
|
+
- method rename `filter_metadata`->`filterMetadata`
|
|
43
|
+
|
|
44
|
+
### Plugin constructor does not merge configs anymore https://github.com/verdaccio/verdaccio/issues/928
|
|
45
|
+
|
|
46
|
+
The plugin receives as first argument `config`, which represents the config of the plugin. Example:
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
// config.yaml
|
|
50
|
+
auth:
|
|
51
|
+
plugin:
|
|
52
|
+
foo: 1
|
|
53
|
+
bar: 2
|
|
54
|
+
|
|
55
|
+
export class Plugin<T> {
|
|
56
|
+
public constructor(config: T, options: PluginOptions) {
|
|
57
|
+
console.log(config);
|
|
58
|
+
// {foo:1, bar: 2}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Patch Changes
|
|
64
|
+
|
|
65
|
+
- Updated dependencies [43f32687]
|
|
66
|
+
- Updated dependencies [9fc2e796]
|
|
67
|
+
- Updated dependencies [62c24b63]
|
|
68
|
+
- @verdaccio/api@6.0.0-6-next.31
|
|
69
|
+
- @verdaccio/core@6.0.0-6-next.48
|
|
70
|
+
- @verdaccio/store@6.0.0-6-next.28
|
|
71
|
+
- @verdaccio/auth@6.0.0-6-next.27
|
|
72
|
+
- @verdaccio/config@6.0.0-6-next.48
|
|
73
|
+
- @verdaccio/loaders@6.0.0-6-next.17
|
|
74
|
+
- verdaccio-audit@11.0.0-6-next.11
|
|
75
|
+
- @verdaccio/web@6.0.0-6-next.35
|
|
76
|
+
- @verdaccio/utils@6.0.0-6-next.16
|
|
77
|
+
- @verdaccio/logger@6.0.0-6-next.16
|
|
78
|
+
- @verdaccio/middleware@6.0.0-6-next.27
|
|
79
|
+
|
|
3
80
|
## 6.0.0-6-next.36
|
|
4
81
|
|
|
5
82
|
### Patch Changes
|
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,18 +70,18 @@ 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
|
-
const plugins = (0, _loaders.loadPlugin)(config, config.middlewares, plugin_params, function (plugin) {
|
|
78
|
+
}, function (plugin) {
|
|
80
79
|
return plugin.register_middlewares;
|
|
81
80
|
});
|
|
82
81
|
|
|
83
|
-
if (
|
|
82
|
+
if (plugins.length === 0) {
|
|
83
|
+
_logger.logger.info('none middleware plugins has been defined, adding audit middleware by default');
|
|
84
|
+
|
|
84
85
|
plugins.push(new _verdaccioAudit.default({ ...config,
|
|
85
86
|
enabled: true,
|
|
86
87
|
strict_ssl: true
|
|
@@ -98,7 +99,7 @@ const defineAPI = function (config, storage) {
|
|
|
98
99
|
app.use((0, _api.default)(config, auth, storage)); // For WebUI & WebUI API
|
|
99
100
|
|
|
100
101
|
if (_lodash.default.get(config, 'web.enable', true)) {
|
|
101
|
-
app.use((0, _web.default)(config, auth, storage));
|
|
102
|
+
app.use(await (0, _web.default)(config, auth, storage));
|
|
102
103
|
} else {
|
|
103
104
|
app.get('/', function (req, res, next) {
|
|
104
105
|
next(_core.errorUtils.getNotFound(_core.API_ERROR.WEB_DISABLED));
|
|
@@ -131,15 +132,11 @@ const defineAPI = function (config, storage) {
|
|
|
131
132
|
return app;
|
|
132
133
|
};
|
|
133
134
|
|
|
134
|
-
var
|
|
135
|
+
var startServer = async function startServer(configHash) {
|
|
135
136
|
debug('start server');
|
|
136
|
-
const config = new _config.Config(
|
|
137
|
+
const config = new _config.Config({ ...configHash
|
|
138
|
+
}); // register middleware plugins
|
|
137
139
|
|
|
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
140
|
debug('loaded filter plugin'); // @ts-ignore
|
|
144
141
|
|
|
145
142
|
const storage = new _store.Storage(config);
|
|
@@ -147,7 +144,7 @@ var _default = async function _default(configHash) {
|
|
|
147
144
|
try {
|
|
148
145
|
// waits until init calls have been initialized
|
|
149
146
|
debug('storage init start');
|
|
150
|
-
await storage.init(config
|
|
147
|
+
await storage.init(config);
|
|
151
148
|
debug('storage init end');
|
|
152
149
|
} catch (err) {
|
|
153
150
|
_logger.logger.error({
|
|
@@ -157,8 +154,8 @@ var _default = async function _default(configHash) {
|
|
|
157
154
|
throw new Error(err);
|
|
158
155
|
}
|
|
159
156
|
|
|
160
|
-
return defineAPI(config, storage);
|
|
157
|
+
return await defineAPI(config, storage);
|
|
161
158
|
};
|
|
162
159
|
|
|
163
|
-
exports.default =
|
|
160
|
+
exports.default = startServer;
|
|
164
161
|
//# 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, { Application } 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, IBasicAuth } from '@verdaccio/auth';\nimport { Config as AppConfig } from '@verdaccio/config';\nimport { API_ERROR, HTTP_STATUS, errorUtils } 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, IPlugin } 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\nexport interface IPluginMiddleware<T> extends IPlugin<T> {\n register_middlewares(app: any, auth: IBasicAuth<T>, storage: Storage): void;\n}\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: Application = 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: IPluginMiddleware<IConfig>[] = await asyncLoadPlugin(\n config.middlewares,\n {\n config,\n logger,\n },\n function (plugin: IPluginMiddleware<IConfig>) {\n return plugin.register_middlewares;\n }\n );\n\n if (plugins.length === 0) {\n logger.info('none middleware plugins has been defined, adding audit middleware by default');\n plugins.push(\n new AuditMiddleware({ ...config, enabled: true, strict_ssl: true }, { config, logger })\n );\n }\n\n plugins.forEach((plugin: IPluginMiddleware<IConfig>) => {\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;;;;AAMA,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,GAAgB,GAAG,IAAAC,gBAAA,GAAzB;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,GA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AAX;IACD;EACF,CApBD;EAsBA9C,GAAG,CAACU,GAAJ,CAAQ8C,iBAAR;EAEA,OAAOxD,GAAP;AACD,CAnGD;;IAqG+ByD,W,GAAf,eAAeA,WAAf,CAA2BC,UAA3B,EAAiE;EAC/ElE,KAAK,CAAC,cAAD,CAAL;EACA,MAAMG,MAAe,GAAG,IAAIgE,cAAJ,CAAc,EAAE,GAAGD;EAAL,CAAd,CAAxB,CAF+E,CAG/E;;EACAlE,KAAK,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.37",
|
|
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.31",
|
|
34
|
+
"@verdaccio/auth": "6.0.0-6-next.27",
|
|
35
|
+
"@verdaccio/core": "6.0.0-6-next.48",
|
|
36
|
+
"@verdaccio/config": "6.0.0-6-next.48",
|
|
37
|
+
"@verdaccio/loaders": "6.0.0-6-next.17",
|
|
38
|
+
"@verdaccio/logger": "6.0.0-6-next.16",
|
|
39
|
+
"@verdaccio/middleware": "6.0.0-6-next.27",
|
|
40
|
+
"@verdaccio/store": "6.0.0-6-next.28",
|
|
41
|
+
"@verdaccio/utils": "6.0.0-6-next.16",
|
|
42
|
+
"@verdaccio/web": "6.0.0-6-next.35",
|
|
43
|
+
"verdaccio-audit": "11.0.0-6-next.11",
|
|
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.60",
|
|
53
|
+
"@verdaccio/proxy": "6.0.0-6-next.26",
|
|
54
|
+
"@verdaccio/test-helper": "2.0.0-6-next.5",
|
|
55
55
|
"http-errors": "1.8.1"
|
|
56
56
|
},
|
|
57
57
|
"funding": {
|
package/src/server.ts
CHANGED
|
@@ -11,12 +11,12 @@ import apiEndpoint from '@verdaccio/api';
|
|
|
11
11
|
import { Auth, IBasicAuth } from '@verdaccio/auth';
|
|
12
12
|
import { Config as AppConfig } from '@verdaccio/config';
|
|
13
13
|
import { API_ERROR, HTTP_STATUS, errorUtils } from '@verdaccio/core';
|
|
14
|
-
import {
|
|
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, IPlugin
|
|
19
|
+
import { Config as IConfig, IPlugin } from '@verdaccio/types';
|
|
20
20
|
import webMiddleware from '@verdaccio/web';
|
|
21
21
|
|
|
22
22
|
import { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types/custom';
|
|
@@ -29,8 +29,9 @@ export interface IPluginMiddleware<T> extends IPlugin<T> {
|
|
|
29
29
|
|
|
30
30
|
const debug = buildDebug('verdaccio:server');
|
|
31
31
|
|
|
32
|
-
const defineAPI = function (config: IConfig, storage: Storage): any {
|
|
32
|
+
const defineAPI = async function (config: IConfig, storage: Storage): Promise<any> {
|
|
33
33
|
const auth: Auth = new Auth(config);
|
|
34
|
+
await auth.init();
|
|
34
35
|
const app: Application = express();
|
|
35
36
|
const limiter = new RateLimit(config.serverSettings.rateLimit);
|
|
36
37
|
// run in production mode by default, just in case
|
|
@@ -62,27 +63,21 @@ const defineAPI = function (config: IConfig, storage: Storage): any {
|
|
|
62
63
|
hookDebug(app, config.configPath);
|
|
63
64
|
}
|
|
64
65
|
|
|
65
|
-
|
|
66
|
-
const plugin_params = {
|
|
67
|
-
config: config,
|
|
68
|
-
logger: logger,
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const plugins: IPluginMiddleware<IConfig>[] = loadPlugin(
|
|
72
|
-
config,
|
|
66
|
+
const plugins: IPluginMiddleware<IConfig>[] = await asyncLoadPlugin(
|
|
73
67
|
config.middlewares,
|
|
74
|
-
|
|
68
|
+
{
|
|
69
|
+
config,
|
|
70
|
+
logger,
|
|
71
|
+
},
|
|
75
72
|
function (plugin: IPluginMiddleware<IConfig>) {
|
|
76
73
|
return plugin.register_middlewares;
|
|
77
74
|
}
|
|
78
75
|
);
|
|
79
76
|
|
|
80
|
-
if (
|
|
77
|
+
if (plugins.length === 0) {
|
|
78
|
+
logger.info('none middleware plugins has been defined, adding audit middleware by default');
|
|
81
79
|
plugins.push(
|
|
82
|
-
new AuditMiddleware(
|
|
83
|
-
{ ...config, enabled: true, strict_ssl: true },
|
|
84
|
-
{ config, logger: logger }
|
|
85
|
-
)
|
|
80
|
+
new AuditMiddleware({ ...config, enabled: true, strict_ssl: true }, { config, logger })
|
|
86
81
|
);
|
|
87
82
|
}
|
|
88
83
|
|
|
@@ -96,7 +91,7 @@ const defineAPI = function (config: IConfig, storage: Storage): any {
|
|
|
96
91
|
|
|
97
92
|
// For WebUI & WebUI API
|
|
98
93
|
if (_.get(config, 'web.enable', true)) {
|
|
99
|
-
app.use(webMiddleware(config, auth, storage));
|
|
94
|
+
app.use(await webMiddleware(config, auth, storage));
|
|
100
95
|
} else {
|
|
101
96
|
app.get('/', function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {
|
|
102
97
|
next(errorUtils.getNotFound(API_ERROR.WEB_DISABLED));
|
|
@@ -135,31 +130,21 @@ const defineAPI = function (config: IConfig, storage: Storage): any {
|
|
|
135
130
|
return app;
|
|
136
131
|
};
|
|
137
132
|
|
|
138
|
-
export default (async function (configHash: ConfigYaml): Promise<any> {
|
|
133
|
+
export default (async function startServer(configHash: ConfigYaml): Promise<any> {
|
|
139
134
|
debug('start server');
|
|
140
|
-
const config: IConfig = new AppConfig(
|
|
135
|
+
const config: IConfig = new AppConfig({ ...configHash } as any);
|
|
141
136
|
// 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
137
|
debug('loaded filter plugin');
|
|
153
138
|
// @ts-ignore
|
|
154
139
|
const storage: Storage = new Storage(config);
|
|
155
140
|
try {
|
|
156
141
|
// waits until init calls have been initialized
|
|
157
142
|
debug('storage init start');
|
|
158
|
-
await storage.init(config
|
|
143
|
+
await storage.init(config);
|
|
159
144
|
debug('storage init end');
|
|
160
145
|
} catch (err: any) {
|
|
161
146
|
logger.error({ error: err.msg }, 'storage has failed: @{error}');
|
|
162
147
|
throw new Error(err);
|
|
163
148
|
}
|
|
164
|
-
return defineAPI(config, storage);
|
|
149
|
+
return await defineAPI(config, storage);
|
|
165
150
|
});
|