@verdaccio/node-api 6.0.0-6-next.32 → 6.0.0-6-next.33
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 +59 -0
- package/build/cli-utils.js.map +1 -1
- package/build/experiments.js.map +1 -1
- package/build/index.js.map +1 -1
- package/build/server.d.ts +4 -4
- package/build/server.js +52 -34
- package/build/server.js.map +1 -1
- package/jest.config.js +8 -1
- package/package.json +13 -13
- package/src/server.ts +61 -49
- package/test/run-server.spec.ts +3 -4
- package/tsconfig.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,64 @@
|
|
|
1
1
|
# @verdaccio/node-api
|
|
2
2
|
|
|
3
|
+
## 6.0.0-6-next.33
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 292c0a37: feat!: replace deprecated request dependency by got
|
|
8
|
+
|
|
9
|
+
This is a big refactoring of the core, fetching dependencies, improve code, more tests and better stability. This is essential for the next release, will take some time but would allow modularize more the core.
|
|
10
|
+
|
|
11
|
+
## Notes
|
|
12
|
+
|
|
13
|
+
- Remove deprecated `request` by other `got`, retry improved, custom Agent ( got does not include it built-in)
|
|
14
|
+
- Remove `async` dependency from storage (used by core) it was linked with proxy somehow safe to remove now
|
|
15
|
+
- Refactor with promises instead callback wherever is possible
|
|
16
|
+
- ~Document the API~
|
|
17
|
+
- Improve testing, integration tests
|
|
18
|
+
- Bugfix
|
|
19
|
+
- Clean up old validations
|
|
20
|
+
- Improve performance
|
|
21
|
+
|
|
22
|
+
## 💥 Breaking changes
|
|
23
|
+
|
|
24
|
+
- Plugin API methods were callbacks based are returning promises, this will break current storage plugins, check documentation for upgrade.
|
|
25
|
+
- Write Tarball, Read Tarball methods parameters change, a new set of options like `AbortController` signals are being provided to the `addAbortSignal` can be internally used with Streams when a request is aborted. eg: `addAbortSignal(signal, fs.createReadStream(pathName));`
|
|
26
|
+
- `@verdaccio/streams` stream abort support is legacy is being deprecated removed
|
|
27
|
+
- Remove AWS and Google Cloud packages for future refactoring [#2574](https://github.com/verdaccio/verdaccio/pull/2574).
|
|
28
|
+
|
|
29
|
+
### Minor Changes
|
|
30
|
+
|
|
31
|
+
- 00d1d2a1: chore: env variable for launch fastify
|
|
32
|
+
|
|
33
|
+
- Update fastify to major release `v4.3.0`
|
|
34
|
+
- Update CLI launcher
|
|
35
|
+
|
|
36
|
+
via CLI
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
VERDACCIO_SERVER=fastify verdaccio
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
with docker
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
docker run -it --rm --name verdaccio \
|
|
46
|
+
-e "VERDACCIO_SERVER=8080" -p 8080:8080 \
|
|
47
|
+
-e "VERDACCIO_SERVER=fastify" \
|
|
48
|
+
verdaccio/verdaccio
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Patch Changes
|
|
52
|
+
|
|
53
|
+
- Updated dependencies [292c0a37]
|
|
54
|
+
- Updated dependencies [a3a209b5]
|
|
55
|
+
- Updated dependencies [00d1d2a1]
|
|
56
|
+
- @verdaccio/config@6.0.0-6-next.15
|
|
57
|
+
- @verdaccio/core@6.0.0-6-next.6
|
|
58
|
+
- @verdaccio/logger@6.0.0-6-next.12
|
|
59
|
+
- @verdaccio/server@6.0.0-6-next.32
|
|
60
|
+
- @verdaccio/server-fastify@6.0.0-6-next.24
|
|
61
|
+
|
|
3
62
|
## 6.0.0-6-next.32
|
|
4
63
|
|
|
5
64
|
### Patch Changes
|
package/build/cli-utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"cli-utils.js","names":["DEFAULT_PORT","DEFAULT_PROTOCOL","DEFAULT_DOMAIN","parseAddress","urlAddress","urlPattern","exec","proto","host","port","path","getListListenAddresses","argListen","configListen","addresses","Array","isArray","process","emitWarning","map","addr","parsedAddr","warningUtils","emit","Codes","VERWAR004","filter","Boolean"],"sources":["../src/cli-utils.ts"],"sourcesContent":["import { warningUtils } from '@verdaccio/core';\n\nexport const DEFAULT_PORT = '4873';\nexport const DEFAULT_PROTOCOL = 'http';\nexport const DEFAULT_DOMAIN = 'localhost';\n/**\n * Parse an internet address\n * Allow:\n - https:localhost:1234 - protocol + host + port\n - localhost:1234 - host + port\n - 1234 - port\n - http::1234 - protocol + port\n - https://localhost:443/ - full url + https\n - http://[::1]:443/ - ipv6\n - unix:/tmp/http.sock - unix sockets\n - https://unix:/tmp/http.sock - unix sockets (https)\n * @param {*} urlAddress the internet address definition\n * @return {Object|Null} literal object that represent the address parsed\n */\nexport function parseAddress(urlAddress: any): any {\n //\n // TODO: refactor it to something more reasonable?\n //\n // protocol : // ( host )|( ipv6 ): port /\n let urlPattern = /^((https?):(\\/\\/)?)?((([^\\/:]*)|\\[([^\\[\\]]+)\\]):)?(\\d+)\\/?$/.exec(urlAddress);\n\n if (urlPattern) {\n return {\n proto: urlPattern[2] || DEFAULT_PROTOCOL,\n host: urlPattern[6] || urlPattern[7] || DEFAULT_DOMAIN,\n port: urlPattern[8] || DEFAULT_PORT,\n };\n }\n\n urlPattern = /^((https?):(\\/\\/)?)?unix:(.*)$/.exec(urlAddress);\n\n if (urlPattern) {\n return {\n proto: urlPattern[2] || DEFAULT_PROTOCOL,\n path: urlPattern[4],\n };\n }\n\n return null;\n}\n\n/**\n * Retrieve all addresses defined in the config file.\n * Verdaccio is able to listen multiple ports\n * @param {String} argListen\n * @param {String} configListen\n * eg:\n * listen:\n - localhost:5555\n - localhost:5557\n @return {Array}\n */\nexport function getListListenAddresses(argListen: string | void, configListen: any): any {\n // command line || config file || default\n let addresses;\n if (argListen) {\n addresses = [argListen];\n } else if (Array.isArray(configListen)) {\n addresses = configListen;\n process.emitWarning('multiple addresses will be deprecated in the next major, only use one');\n } else if (configListen) {\n addresses = [configListen];\n } else {\n addresses = [DEFAULT_PORT];\n }\n addresses = addresses\n .map(function (addr): string {\n const parsedAddr = parseAddress(addr);\n\n if (!parsedAddr) {\n warningUtils.emit(warningUtils.Codes.VERWAR004, addr);\n }\n\n return parsedAddr;\n })\n .filter(Boolean);\n\n return addresses;\n}\n"],"mappings":";;;;;;;;;AAAA;;AAEO,MAAMA,YAAY,GAAG,MAArB;;AACA,MAAMC,gBAAgB,GAAG,MAAzB;;AACA,MAAMC,cAAc,GAAG,WAAvB;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;AACO,SAASC,YAAT,CAAsBC,UAAtB,EAA4C;EACjD;EACA;EACA;EACA;EACA,IAAIC,UAAU,GAAG,8DAA8DC,IAA9D,CAAmEF,UAAnE,CAAjB;;EAEA,IAAIC,UAAJ,EAAgB;IACd,OAAO;MACLE,KAAK,EAAEF,UAAU,CAAC,CAAD,CAAV,IAAiBJ,gBADnB;MAELO,IAAI,EAAEH,UAAU,CAAC,CAAD,CAAV,IAAiBA,UAAU,CAAC,CAAD,CAA3B,IAAkCH,cAFnC;MAGLO,IAAI,EAAEJ,UAAU,CAAC,CAAD,CAAV,IAAiBL;IAHlB,CAAP;EAKD;;EAEDK,UAAU,GAAG,iCAAiCC,IAAjC,CAAsCF,UAAtC,CAAb;;EAEA,IAAIC,UAAJ,EAAgB;IACd,OAAO;MACLE,KAAK,EAAEF,UAAU,CAAC,CAAD,CAAV,IAAiBJ,gBADnB;MAELS,IAAI,EAAEL,UAAU,CAAC,CAAD;IAFX,CAAP;EAID;;EAED,OAAO,IAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASM,sBAAT,CAAgCC,SAAhC,EAA0DC,YAA1D,EAAkF;EACvF;EACA,IAAIC,SAAJ;;EACA,IAAIF,SAAJ,EAAe;IACbE,SAAS,GAAG,CAACF,SAAD,CAAZ;EACD,CAFD,MAEO,IAAIG,KAAK,CAACC,OAAN,CAAcH,YAAd,CAAJ,EAAiC;IACtCC,SAAS,GAAGD,YAAZ;IACAI,OAAO,CAACC,WAAR,CAAoB,uEAApB;EACD,CAHM,MAGA,IAAIL,YAAJ,EAAkB;IACvBC,SAAS,GAAG,CAACD,YAAD,CAAZ;EACD,CAFM,MAEA;IACLC,SAAS,GAAG,CAACd,YAAD,CAAZ;EACD;;EACDc,SAAS,GAAGA,SAAS,CAClBK,GADS,CACL,UAAUC,IAAV,EAAwB;IAC3B,MAAMC,UAAU,GAAGlB,YAAY,CAACiB,IAAD,CAA/B;;IAEA,IAAI,CAACC,UAAL,EAAiB;MACfC,kBAAA,CAAaC,IAAb,CAAkBD,kBAAA,CAAaE,KAAb,CAAmBC,SAArC,EAAgDL,IAAhD;IACD;;IAED,OAAOC,UAAP;EACD,CATS,EAUTK,MAVS,CAUFC,OAVE,CAAZ;EAYA,OAAOb,SAAP;AACD"}
|
package/build/experiments.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"experiments.js","names":["displayExperimentsInfoBox","flags","experimentList","Object","keys","length","logger","warn","forEach","experiment","info"],"sources":["../src/experiments.ts"],"sourcesContent":["import { logger } from '@verdaccio/logger';\n\nexport function displayExperimentsInfoBox(flags) {\n if (!flags) {\n return;\n }\n\n const experimentList = Object.keys(flags);\n if (experimentList.length >= 1) {\n logger.warn(\n // eslint-disable-next-line max-len\n `experiments are enabled, it is recommended do not use experiments in production comment out this section to disable it`\n );\n experimentList.forEach((experiment) => {\n // eslint-disable-next-line max-len\n logger.info(\n `support for experiment [${experiment}] ${\n flags[experiment] ? 'is enabled' : ' is disabled'\n }`\n );\n });\n }\n}\n"],"mappings":";;;;;;;AAAA;;AAEO,SAASA,yBAAT,CAAmCC,KAAnC,EAA0C;EAC/C,IAAI,CAACA,KAAL,EAAY;IACV;EACD;;EAED,MAAMC,cAAc,GAAGC,MAAM,CAACC,IAAP,CAAYH,KAAZ,CAAvB;;EACA,IAAIC,cAAc,CAACG,MAAf,IAAyB,CAA7B,EAAgC;IAC9BC,cAAA,CAAOC,IAAP,EACE;IACC,wHAFH;;IAIAL,cAAc,CAACM,OAAf,CAAwBC,UAAD,IAAgB;MACrC;MACAH,cAAA,CAAOI,IAAP,CACG,2BAA0BD,UAAW,KACpCR,KAAK,CAACQ,UAAD,CAAL,GAAoB,YAApB,GAAmC,cACpC,EAHH;IAKD,CAPD;EAQD;AACF"}
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["export { initServer, runServer } from './server';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA"}
|
package/build/server.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ConfigYaml } from '@verdaccio/types';
|
|
2
2
|
/**
|
|
3
3
|
* Return a native HTTP/HTTPS server instance
|
|
4
4
|
* @param config
|
|
5
5
|
* @param addr
|
|
6
6
|
* @param app
|
|
7
7
|
*/
|
|
8
|
-
export declare function createServerFactory(config:
|
|
8
|
+
export declare function createServerFactory(config: ConfigYaml, addr: any, app: any): any;
|
|
9
9
|
/**
|
|
10
10
|
* Start the server on the port defined
|
|
11
11
|
* @param config
|
|
@@ -13,7 +13,7 @@ export declare function createServerFactory(config: ConfigRuntime, addr: any, ap
|
|
|
13
13
|
* @param version
|
|
14
14
|
* @param pkgName
|
|
15
15
|
*/
|
|
16
|
-
export declare function initServer(config:
|
|
16
|
+
export declare function initServer(config: ConfigYaml, port: string | void, version: string, pkgName: string): Promise<void>;
|
|
17
17
|
/**
|
|
18
18
|
* Exposes a server factory to be instantiated programmatically.
|
|
19
19
|
*
|
|
@@ -25,4 +25,4 @@ export declare function initServer(config: ConfigRuntime, port: string | void, v
|
|
|
25
25
|
});
|
|
26
26
|
* @param config
|
|
27
27
|
*/
|
|
28
|
-
export declare function runServer(config?: string |
|
|
28
|
+
export declare function runServer(config?: string | ConfigYaml): Promise<any>;
|
package/build/server.js
CHANGED
|
@@ -29,6 +29,8 @@ var _logger = require("@verdaccio/logger");
|
|
|
29
29
|
|
|
30
30
|
var _server = _interopRequireDefault(require("@verdaccio/server"));
|
|
31
31
|
|
|
32
|
+
var _serverFastify = _interopRequireDefault(require("@verdaccio/server-fastify"));
|
|
33
|
+
|
|
32
34
|
var _cliUtils = require("./cli-utils");
|
|
33
35
|
|
|
34
36
|
var _experiments = require("./experiments");
|
|
@@ -135,44 +137,60 @@ async function initServer(config, port, version, pkgName) {
|
|
|
135
137
|
const [addr] = (0, _cliUtils.getListListenAddresses)(port, config.listen);
|
|
136
138
|
const logger = (0, _logger.setup)(config === null || config === void 0 ? void 0 : config.log);
|
|
137
139
|
(0, _experiments.displayExperimentsInfoBox)(config.flags);
|
|
138
|
-
|
|
139
|
-
const serverFactory = createServerFactory(config, addr, app);
|
|
140
|
-
serverFactory.listen(addr.port || addr.path, addr.host, () => {
|
|
141
|
-
// send a message for test
|
|
142
|
-
if ((0, _lodash.isFunction)(process.send)) {
|
|
143
|
-
process.send({
|
|
144
|
-
verdaccio_started: true
|
|
145
|
-
});
|
|
146
|
-
}
|
|
140
|
+
let app;
|
|
147
141
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}) : _url.default.format({
|
|
152
|
-
protocol: addr.proto,
|
|
153
|
-
hostname: addr.host,
|
|
142
|
+
if (process.env.VERDACCIO_SERVER === 'fastify') {
|
|
143
|
+
app = await (0, _serverFastify.default)(config);
|
|
144
|
+
app.listen({
|
|
154
145
|
port: addr.port,
|
|
155
|
-
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
146
|
+
host: addr.host
|
|
147
|
+
}, err => {
|
|
148
|
+
if (err) {
|
|
149
|
+
reject(err);
|
|
150
|
+
} else {
|
|
151
|
+
resolve();
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
} else {
|
|
155
|
+
app = await (0, _server.default)(config);
|
|
156
|
+
const serverFactory = createServerFactory(config, addr, app);
|
|
157
|
+
serverFactory.listen(addr.port || addr.path, addr.host, () => {
|
|
158
|
+
// send a message for test
|
|
159
|
+
if ((0, _lodash.isFunction)(process.send)) {
|
|
160
|
+
process.send({
|
|
161
|
+
verdaccio_started: true
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const addressServer = `${addr.path ? _url.default.format({
|
|
166
|
+
protocol: 'unix',
|
|
167
|
+
pathname: addr.path
|
|
168
|
+
}) : _url.default.format({
|
|
169
|
+
protocol: addr.proto,
|
|
170
|
+
hostname: addr.host,
|
|
171
|
+
port: addr.port,
|
|
172
|
+
pathname: '/'
|
|
173
|
+
})}`;
|
|
174
|
+
logger.info(`http address ${addressServer}`);
|
|
175
|
+
logger.info(`version: ${version}`);
|
|
176
|
+
resolve();
|
|
177
|
+
}).on('error', function (err) {
|
|
178
|
+
reject(err);
|
|
179
|
+
process.exitCode = 1;
|
|
170
180
|
});
|
|
171
|
-
}
|
|
172
181
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
182
|
+
function handleShutdownGracefully() {
|
|
183
|
+
logger.warn('received shutdown signal - closing server gracefully...');
|
|
184
|
+
serverFactory.close(() => {
|
|
185
|
+
logger.info('server closed.');
|
|
186
|
+
process.exit(0);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) {
|
|
191
|
+
// Use once() so that receiving double signals exit the app.
|
|
192
|
+
process.once(signal, handleShutdownGracefully);
|
|
193
|
+
}
|
|
176
194
|
}
|
|
177
195
|
});
|
|
178
196
|
}
|
package/build/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/server.ts"],"names":["debug","unlinkAddressPath","addr","path","fs","existsSync","unlinkSync","createServerFactory","config","app","serverFactory","proto","httpsOptions","secureOptions","constants","SSL_OP_NO_SSLv2","SSL_OP_NO_SSLv3","keyCertConfig","https","pfxConfig","key","cert","pfx","Error","passphrase","readFileSync","ca","createServer","err","message","http","server","keepAliveTimeout","initServer","port","version","pkgName","Promise","resolve","reject","listen","logger","log","flags","host","process","send","verdaccio_started","addressServer","url","format","protocol","pathname","hostname","info","on","exitCode","handleShutdownGracefully","fatal","close","exit","signal","once","runServer","configurationParsed","undefined","configPathLocation","_","isObject","API_ERROR","CONFIG_BAD_FORMAT"],"mappings":";;;;;;;;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AAEA;;AAGA;;AACA;;;;;;;;AAjBA;AAmBA,MAAMA,KAAK,GAAG,oBAAW,oBAAX,CAAd;;AAEA,SAASC,iBAAT,CAA2BC,IAA3B,EAAiC;AAC/B,MAAIA,IAAI,CAACC,IAAL,IAAaC,YAAGC,UAAH,CAAcH,IAAI,CAACC,IAAnB,CAAjB,EAA2C;AACzCC,gBAAGE,UAAH,CAAcJ,IAAI,CAACC,IAAnB;AACD;AACF;AAED;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASI,mBAAT,CAA6BC,MAA7B,EAAoDN,IAApD,EAA0DO,GAA1D,EAA+D;AACpE,MAAIC,aAAJ;;AACA,MAAIR,IAAI,CAACS,KAAL,KAAe,OAAnB,EAA4B;AAC1BX,IAAAA,KAAK,CAAC,eAAD,CAAL;;AACA,QAAI;AACF,UAAIY,YAAY,GAAG;AACjB;AACAC,QAAAA,aAAa,EAAEC,mBAAUC,eAAV,GAA4BD,mBAAUE;AAFpC,OAAnB;AAKA,YAAMC,aAAa,GAAGT,MAAM,CAACU,KAA7B;AACA,YAAMC,SAAS,GAAGX,MAAM,CAACU,KAAzB,CAPE,CASF;;AACA,UAAI,EAAGD,aAAa,CAAC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AAmB,GAAG,6BAAgBE,kBAAhB,CAAtB;AACD,GAHD,MAGO,IAAIC,gBAAEC,QAAF,CAAW5D,MAAX,CAAJ,EAAwB;AAC7BwD,IAAAA,mBAAmB,GAAGxD,MAAtB;AACD,GAFM,MAEA;AACL,UAAM,IAAIe,KAAJ,CAAU8C,gBAAUC,iBAApB,CAAN;AACD;;AAED,qBAAMN,mBAAmB,CAACtB,GAA1B;AACA,8CAA0BsB,mBAAmB,CAACrB,KAA9C,EAZ6E,CAa7E;;AACA,QAAM,CAACzC,IAAD,IAAS,sCAAuB+D,SAAvB,EAAkCD,mBAAmB,CAACxB,MAAtD,CAAf;AACA,QAAM/B,GAAG,GAAG,MAAM,qBAAOuD,mBAAP,CAAlB;AACA,SAAOzD,mBAAmB,CAACyD,mBAAD,EAAsB9D,IAAtB,EAA4BO,GAA5B,CAA1B;AACD","sourcesContent":["/* eslint-disable */\nimport constants from 'constants';\nimport buildDebug from 'debug';\nimport fs from 'fs';\nimport http from 'http';\nimport https from 'https';\nimport _, { assign, isFunction } from 'lodash';\nimport url from 'url';\n\nimport { findConfigFile, parseConfigFile } from '@verdaccio/config';\nimport { API_ERROR } from '@verdaccio/core';\nimport { setup } from '@verdaccio/logger';\nimport { LoggerConfigItem } from '@verdaccio/logger/src/logger';\nimport server from '@verdaccio/server';\nimport { ConfigRuntime, HttpsConfKeyCert, HttpsConfPfx } from '@verdaccio/types';\n\nimport { getListListenAddresses } from './cli-utils';\nimport { displayExperimentsInfoBox } from './experiments';\n\nconst debug = buildDebug('verdaccio:node-api');\n\nfunction unlinkAddressPath(addr) {\n if (addr.path && fs.existsSync(addr.path)) {\n fs.unlinkSync(addr.path);\n }\n}\n\n/**\n * Return a native HTTP/HTTPS server instance\n * @param config\n * @param addr\n * @param app\n */\nexport function createServerFactory(config: ConfigRuntime, addr, app) {\n let serverFactory;\n if (addr.proto === 'https') {\n debug('https enabled');\n try {\n let httpsOptions = {\n // disable insecure SSLv2 and SSLv3\n secureOptions: constants.SSL_OP_NO_SSLv2 | constants.SSL_OP_NO_SSLv3,\n };\n\n const keyCertConfig = config.https as HttpsConfKeyCert;\n const pfxConfig = config.https as HttpsConfPfx;\n\n // https must either have key and cert or a pfx and (optionally) a passphrase\n if (!((keyCertConfig.key && keyCertConfig.cert) || pfxConfig.pfx)) {\n // logHTTPSError(configPath);\n throw Error('bad format https configuration');\n }\n\n if (pfxConfig.pfx) {\n const { pfx, passphrase } = pfxConfig;\n httpsOptions = assign(httpsOptions, {\n pfx: fs.readFileSync(pfx),\n passphrase: passphrase || '',\n });\n } else {\n const { key, cert, ca } = keyCertConfig;\n httpsOptions = assign(httpsOptions, {\n key: fs.readFileSync(key),\n cert: fs.readFileSync(cert),\n ...(ca && {\n ca: fs.readFileSync(ca),\n }),\n });\n }\n // TODO: enable http2 as feature\n // if (config.server.http2) <-- check if force http2\n serverFactory = https.createServer(httpsOptions, app);\n } catch (err: any) {\n throw new Error(`cannot create https server: ${err.message}`);\n }\n } else {\n // http\n debug('http enabled');\n serverFactory = http.createServer(app);\n }\n\n if (\n config.server &&\n typeof config.server.keepAliveTimeout !== 'undefined' &&\n // @ts-ignore\n config.server.keepAliveTimeout !== 'null'\n ) {\n // library definition for node is not up to date (doesn't contain recent 8.0 changes)\n serverFactory.keepAliveTimeout = config.server.keepAliveTimeout * 1000;\n }\n // FIXE: I could not find the reason of this code.\n unlinkAddressPath(addr);\n\n return serverFactory;\n}\n\n/**\n * Start the server on the port defined\n * @param config\n * @param port\n * @param version\n * @param pkgName\n */\nexport async function initServer(\n config: ConfigRuntime,\n port: string | void,\n version: string,\n pkgName: string\n): Promise<void> {\n return new Promise(async (resolve, reject) => {\n // FIXME: get only the first match, the multiple address will be removed\n const [addr] = getListListenAddresses(port, config.listen);\n const logger = setup(config?.log as LoggerConfigItem);\n displayExperimentsInfoBox(config.flags);\n const app = await server(config);\n const serverFactory = createServerFactory(config, addr, app);\n serverFactory\n .listen(addr.port || addr.path, addr.host, (): void => {\n // send a message for test\n if (isFunction(process.send)) {\n process.send({\n verdaccio_started: true,\n });\n }\n const addressServer = `${\n addr.path\n ? url.format({\n protocol: 'unix',\n pathname: addr.path,\n })\n : url.format({\n protocol: addr.proto,\n hostname: addr.host,\n port: addr.port,\n pathname: '/',\n })\n }`;\n logger.info(`http address ${addressServer}`);\n logger.info(`version: ${version}`);\n resolve();\n })\n .on('error', function (err): void {\n reject(err);\n process.exitCode = 1;\n });\n\n function handleShutdownGracefully() {\n logger.fatal('received shutdown signal - closing server gracefully...');\n serverFactory.close(() => {\n logger.info('server closed.');\n process.exit(0);\n });\n }\n\n for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) {\n // Use once() so that receiving double signals exit the app.\n process.once(signal, handleShutdownGracefully);\n }\n });\n}\n\n/**\n * Exposes a server factory to be instantiated programmatically.\n *\n const app = await runServer(); // default configuration\n const app = await runServer('./config/config.yaml');\n const app = await runServer({ configuration });\n app.listen(4000, (event) => {\n // do something\n });\n * @param config\n */\nexport async function runServer(config?: string | ConfigRuntime): Promise<any> {\n let configurationParsed: ConfigRuntime;\n if (config === undefined || typeof config === 'string') {\n const configPathLocation = findConfigFile(config);\n configurationParsed = parseConfigFile(configPathLocation) as ConfigRuntime;\n } else if (_.isObject(config)) {\n configurationParsed = config;\n } else {\n throw new Error(API_ERROR.CONFIG_BAD_FORMAT);\n }\n\n setup(configurationParsed.log as LoggerConfigItem);\n displayExperimentsInfoBox(configurationParsed.flags);\n // FIXME: get only the first match, the multiple address will be removed\n const [addr] = getListListenAddresses(undefined, configurationParsed.listen);\n const app = await server(configurationParsed);\n return createServerFactory(configurationParsed, addr, app);\n}\n"],"file":"server.js"}
|
|
1
|
+
{"version":3,"file":"server.js","names":["debug","buildDebug","unlinkAddressPath","addr","path","fs","existsSync","unlinkSync","createServerFactory","config","app","serverFactory","proto","httpsOptions","secureOptions","constants","SSL_OP_NO_SSLv2","SSL_OP_NO_SSLv3","keyCertConfig","https","pfxConfig","key","cert","pfx","Error","passphrase","assign","readFileSync","ca","createServer","err","message","http","server","keepAliveTimeout","initServer","port","version","pkgName","Promise","resolve","reject","getListListenAddresses","listen","logger","setup","log","displayExperimentsInfoBox","flags","process","env","VERDACCIO_SERVER","fastifyServer","host","isFunction","send","verdaccio_started","addressServer","url","format","protocol","pathname","hostname","info","on","exitCode","handleShutdownGracefully","warn","close","exit","signal","once","runServer","configurationParsed","undefined","configPathLocation","findConfigFile","parseConfigFile","_","isObject","API_ERROR","CONFIG_BAD_FORMAT"],"sources":["../src/server.ts"],"sourcesContent":["/* eslint-disable */\nimport constants from 'constants';\nimport buildDebug from 'debug';\nimport fs from 'fs';\nimport http from 'http';\nimport https from 'https';\nimport _, { assign, isFunction } from 'lodash';\nimport url from 'url';\n\nimport { findConfigFile, parseConfigFile } from '@verdaccio/config';\nimport { API_ERROR } from '@verdaccio/core';\nimport { setup } from '@verdaccio/logger';\nimport server from '@verdaccio/server';\nimport fastifyServer from '@verdaccio/server-fastify';\nimport { ConfigYaml, HttpsConfKeyCert, HttpsConfPfx } from '@verdaccio/types';\n\nimport { getListListenAddresses } from './cli-utils';\nimport { displayExperimentsInfoBox } from './experiments';\n\nconst debug = buildDebug('verdaccio:node-api');\n\nfunction unlinkAddressPath(addr) {\n if (addr.path && fs.existsSync(addr.path)) {\n fs.unlinkSync(addr.path);\n }\n}\n\n/**\n * Return a native HTTP/HTTPS server instance\n * @param config\n * @param addr\n * @param app\n */\nexport function createServerFactory(config: ConfigYaml, addr, app) {\n let serverFactory;\n if (addr.proto === 'https') {\n debug('https enabled');\n try {\n let httpsOptions = {\n // disable insecure SSLv2 and SSLv3\n secureOptions: constants.SSL_OP_NO_SSLv2 | constants.SSL_OP_NO_SSLv3,\n };\n\n const keyCertConfig = config.https as HttpsConfKeyCert;\n const pfxConfig = config.https as HttpsConfPfx;\n\n // https must either have key and cert or a pfx and (optionally) a passphrase\n if (!((keyCertConfig.key && keyCertConfig.cert) || pfxConfig.pfx)) {\n // logHTTPSError(configPath);\n throw Error('bad format https configuration');\n }\n\n if (pfxConfig.pfx) {\n const { pfx, passphrase } = pfxConfig;\n httpsOptions = assign(httpsOptions, {\n pfx: fs.readFileSync(pfx),\n passphrase: passphrase || '',\n });\n } else {\n const { key, cert, ca } = keyCertConfig;\n httpsOptions = assign(httpsOptions, {\n key: fs.readFileSync(key),\n cert: fs.readFileSync(cert),\n ...(ca && {\n ca: fs.readFileSync(ca),\n }),\n });\n }\n // TODO: enable http2 as feature\n // if (config.server.http2) <-- check if force http2\n serverFactory = https.createServer(httpsOptions, app);\n } catch (err: any) {\n throw new Error(`cannot create https server: ${err.message}`);\n }\n } else {\n // http\n debug('http enabled');\n serverFactory = http.createServer(app);\n }\n\n if (\n config.server &&\n typeof config.server.keepAliveTimeout !== 'undefined' &&\n // @ts-ignore\n config.server.keepAliveTimeout !== 'null'\n ) {\n // library definition for node is not up to date (doesn't contain recent 8.0 changes)\n serverFactory.keepAliveTimeout = config.server.keepAliveTimeout * 1000;\n }\n // FIXE: I could not find the reason of this code.\n unlinkAddressPath(addr);\n\n return serverFactory;\n}\n\n/**\n * Start the server on the port defined\n * @param config\n * @param port\n * @param version\n * @param pkgName\n */\nexport async function initServer(\n config: ConfigYaml,\n port: string | void,\n version: string,\n pkgName: string\n): Promise<void> {\n return new Promise(async (resolve, reject) => {\n // FIXME: get only the first match, the multiple address will be removed\n const [addr] = getListListenAddresses(port, config.listen);\n const logger = setup(config?.log as any);\n displayExperimentsInfoBox(config.flags);\n\n let app;\n if (process.env.VERDACCIO_SERVER === 'fastify') {\n app = await fastifyServer(config);\n app.listen({ port: addr.port, host: addr.host }, (err) => {\n if (err) {\n reject(err);\n } else {\n resolve();\n }\n });\n } else {\n app = await server(config);\n const serverFactory = createServerFactory(config, addr, app);\n serverFactory\n .listen(addr.port || addr.path, addr.host, (): void => {\n // send a message for test\n if (isFunction(process.send)) {\n process.send({\n verdaccio_started: true,\n });\n }\n const addressServer = `${\n addr.path\n ? url.format({\n protocol: 'unix',\n pathname: addr.path,\n })\n : url.format({\n protocol: addr.proto,\n hostname: addr.host,\n port: addr.port,\n pathname: '/',\n })\n }`;\n logger.info(`http address ${addressServer}`);\n logger.info(`version: ${version}`);\n resolve();\n })\n .on('error', function (err): void {\n reject(err);\n process.exitCode = 1;\n });\n function handleShutdownGracefully() {\n logger.warn('received shutdown signal - closing server gracefully...');\n serverFactory.close(() => {\n logger.info('server closed.');\n process.exit(0);\n });\n }\n\n for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) {\n // Use once() so that receiving double signals exit the app.\n process.once(signal, handleShutdownGracefully);\n }\n }\n });\n}\n\n/**\n * Exposes a server factory to be instantiated programmatically.\n *\n const app = await runServer(); // default configuration\n const app = await runServer('./config/config.yaml');\n const app = await runServer({ configuration });\n app.listen(4000, (event) => {\n // do something\n });\n * @param config\n */\nexport async function runServer(config?: string | ConfigYaml): Promise<any> {\n let configurationParsed: ConfigYaml;\n if (config === undefined || typeof config === 'string') {\n const configPathLocation = findConfigFile(config);\n configurationParsed = parseConfigFile(configPathLocation);\n } else if (_.isObject(config)) {\n configurationParsed = config;\n } else {\n throw new Error(API_ERROR.CONFIG_BAD_FORMAT);\n }\n\n setup(configurationParsed.log as any);\n displayExperimentsInfoBox(configurationParsed.flags);\n // FIXME: get only the first match, the multiple address will be removed\n const [addr] = getListListenAddresses(undefined, configurationParsed.listen);\n const app = await server(configurationParsed);\n return createServerFactory(configurationParsed, addr, app);\n}\n"],"mappings":";;;;;;;;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AAGA;;AACA;;;;;;;;AAjBA;AAmBA,MAAMA,KAAK,GAAG,IAAAC,cAAA,EAAW,oBAAX,CAAd;;AAEA,SAASC,iBAAT,CAA2BC,IAA3B,EAAiC;EAC/B,IAAIA,IAAI,CAACC,IAAL,IAAaC,WAAA,CAAGC,UAAH,CAAcH,IAAI,CAACC,IAAnB,CAAjB,EAA2C;IACzCC,WAAA,CAAGE,UAAH,CAAcJ,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MAAtD,CAAf;EACA,MAAMjC,GAAG,GAAG,MAAM,IAAAuB,eAAA,EAAOwC,mBAAP,CAAlB;EACA,OAAOjE,mBAAmB,CAACiE,mBAAD,EAAsBtE,IAAtB,EAA4BO,GAA5B,CAA1B;AACD"}
|
package/jest.config.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verdaccio/node-api",
|
|
3
|
-
"version": "6.0.0-6-next.
|
|
3
|
+
"version": "6.0.0-6-next.33",
|
|
4
4
|
"description": "node API",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -30,21 +30,21 @@
|
|
|
30
30
|
},
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@verdaccio/core": "6.0.0-6-next.
|
|
34
|
-
"@verdaccio/config": "6.0.0-6-next.
|
|
35
|
-
"@verdaccio/logger": "6.0.0-6-next.
|
|
36
|
-
"@verdaccio/server": "6.0.0-6-next.
|
|
37
|
-
"
|
|
38
|
-
"
|
|
33
|
+
"@verdaccio/core": "6.0.0-6-next.6",
|
|
34
|
+
"@verdaccio/config": "6.0.0-6-next.15",
|
|
35
|
+
"@verdaccio/logger": "6.0.0-6-next.12",
|
|
36
|
+
"@verdaccio/server": "6.0.0-6-next.32",
|
|
37
|
+
"@verdaccio/server-fastify": "6.0.0-6-next.24",
|
|
38
|
+
"core-js": "3.24.1",
|
|
39
|
+
"debug": "4.3.4",
|
|
39
40
|
"lodash": "4.17.21"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
42
|
-
"@types/node": "16.11.
|
|
43
|
-
"@verdaccio/
|
|
44
|
-
"
|
|
45
|
-
"jest-mock-process": "1.4.1",
|
|
43
|
+
"@types/node": "16.11.47",
|
|
44
|
+
"@verdaccio/types": "11.0.0-6-next.13",
|
|
45
|
+
"jest-mock-process": "1.5.1",
|
|
46
46
|
"selfsigned": "1.10.14",
|
|
47
|
-
"supertest": "6.2.
|
|
47
|
+
"supertest": "6.2.4"
|
|
48
48
|
},
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public"
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"build:js": "babel src/ --out-dir build/ --copy-files --extensions \".ts,.tsx\" --source-maps",
|
|
61
61
|
"watch": "pnpm build:js -- --watch",
|
|
62
62
|
"build": "pnpm run build:js && pnpm run build:types",
|
|
63
|
-
"test": "
|
|
63
|
+
"test": "jest"
|
|
64
64
|
},
|
|
65
65
|
"readme": "# @verdaccio/node-api\n\n[](https://opencollective.com/verdaccio)\n[](https://stackshare.io/verdaccio)\n[](https://github.com/verdaccio/verdaccio/blob/master/LICENSE)\n[](https://crowdin.com/project/verdaccio)\n[](https://www.tickgit.com/browse?repo=github.com/verdaccio/verdaccio)\n\n[](https://twitter.com/verdaccio_npm)\n[](https://github.com/verdaccio/verdaccio/stargazers)\n\n## Donations\n\nVerdaccio is run by **volunteers**; nobody is working full-time on it. If you find this project to be useful and would like to support its development, consider making a donation - **your logo might end up in this readme.** 😉\n\n**[Donate](https://opencollective.com/verdaccio)** 💵👍🏻 starting from _\\$1/month_ or just one single contribution.\n\n## Report a vulnerability\n\nIf you want to report a security vulnerability, please follow the steps which we have defined for you in our [security policy](https://github.com/verdaccio/verdaccio/security/policy).\n\n## Open Collective Sponsors\n\nSupport this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/verdaccio#sponsor)]\n\n[](https://opencollective.com/verdaccio/sponsor/0/website)\n[](https://opencollective.com/verdaccio/sponsor/1/website)\n[](https://opencollective.com/verdaccio/sponsor/2/website)\n[](https://opencollective.com/verdaccio/sponsor/3/website)\n[](https://opencollective.com/verdaccio/sponsor/4/website)\n[](https://opencollective.com/verdaccio/sponsor/5/website)\n[](https://opencollective.com/verdaccio/sponsor/6/website)\n[](https://opencollective.com/verdaccio/sponsor/7/website)\n[](https://opencollective.com/verdaccio/sponsor/8/website)\n[](https://opencollective.com/verdaccio/sponsor/9/website)\n\n## Open Collective Backers\n\nThank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/verdaccio#backer)]\n\n[](https://opencollective.com/verdaccio#backers)\n\n## Special Thanks\n\nThanks to the following companies to help us to achieve our goals providing free open source licenses.\n\n[](https://www.jetbrains.com/)\n[](https://crowdin.com/)\n[](https://balsamiq.com/)\n\n## Contributors\n\nThis project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].\n\n[](../../graphs/contributors)\n\n### FAQ / Contact / Troubleshoot\n\nIf you have any issue you can try the following options, do no desist to ask or check our issues database, perhaps someone has asked already what you are looking for.\n\n- [Blog](https://verdaccio.org/blog/)\n- [Donations](https://opencollective.com/verdaccio)\n- [Reporting an issue](https://github.com/verdaccio/verdaccio/blob/master/CONTRIBUTING.md#reporting-a-bug)\n- [Running discussions](https://github.com/verdaccio/verdaccio/issues?q=is%3Aissue+is%3Aopen+label%3Adiscuss)\n- [Chat](http://chat.verdaccio.org/)\n- [Logos](https://verdaccio.org/docs/en/logo)\n- [Docker Examples](https://github.com/verdaccio/docker-examples)\n- [FAQ](https://github.com/verdaccio/verdaccio/issues?utf8=%E2%9C%93&q=is%3Aissue%20label%3Aquestion%20)\n\n### License\n\nVerdaccio is [MIT licensed](https://github.com/verdaccio/verdaccio/blob/master/LICENSE)\n\nThe Verdaccio documentation and logos (excluding /thanks, e.g., .md, .png, .sketch) files within the /assets folder) is\n[Creative Commons licensed](https://github.com/verdaccio/verdaccio/blob/master/LICENSE-docs).\n"
|
|
66
66
|
}
|
package/src/server.ts
CHANGED
|
@@ -10,9 +10,9 @@ import url from 'url';
|
|
|
10
10
|
import { findConfigFile, parseConfigFile } from '@verdaccio/config';
|
|
11
11
|
import { API_ERROR } from '@verdaccio/core';
|
|
12
12
|
import { setup } from '@verdaccio/logger';
|
|
13
|
-
import { LoggerConfigItem } from '@verdaccio/logger/src/logger';
|
|
14
13
|
import server from '@verdaccio/server';
|
|
15
|
-
import
|
|
14
|
+
import fastifyServer from '@verdaccio/server-fastify';
|
|
15
|
+
import { ConfigYaml, HttpsConfKeyCert, HttpsConfPfx } from '@verdaccio/types';
|
|
16
16
|
|
|
17
17
|
import { getListListenAddresses } from './cli-utils';
|
|
18
18
|
import { displayExperimentsInfoBox } from './experiments';
|
|
@@ -31,7 +31,7 @@ function unlinkAddressPath(addr) {
|
|
|
31
31
|
* @param addr
|
|
32
32
|
* @param app
|
|
33
33
|
*/
|
|
34
|
-
export function createServerFactory(config:
|
|
34
|
+
export function createServerFactory(config: ConfigYaml, addr, app) {
|
|
35
35
|
let serverFactory;
|
|
36
36
|
if (addr.proto === 'https') {
|
|
37
37
|
debug('https enabled');
|
|
@@ -101,7 +101,7 @@ export function createServerFactory(config: ConfigRuntime, addr, app) {
|
|
|
101
101
|
* @param pkgName
|
|
102
102
|
*/
|
|
103
103
|
export async function initServer(
|
|
104
|
-
config:
|
|
104
|
+
config: ConfigYaml,
|
|
105
105
|
port: string | void,
|
|
106
106
|
version: string,
|
|
107
107
|
pkgName: string
|
|
@@ -109,51 +109,63 @@ export async function initServer(
|
|
|
109
109
|
return new Promise(async (resolve, reject) => {
|
|
110
110
|
// FIXME: get only the first match, the multiple address will be removed
|
|
111
111
|
const [addr] = getListListenAddresses(port, config.listen);
|
|
112
|
-
const logger = setup(config?.log as
|
|
112
|
+
const logger = setup(config?.log as any);
|
|
113
113
|
displayExperimentsInfoBox(config.flags);
|
|
114
|
-
const app = await server(config);
|
|
115
|
-
const serverFactory = createServerFactory(config, addr, app);
|
|
116
|
-
serverFactory
|
|
117
|
-
.listen(addr.port || addr.path, addr.host, (): void => {
|
|
118
|
-
// send a message for test
|
|
119
|
-
if (isFunction(process.send)) {
|
|
120
|
-
process.send({
|
|
121
|
-
verdaccio_started: true,
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
const addressServer = `${
|
|
125
|
-
addr.path
|
|
126
|
-
? url.format({
|
|
127
|
-
protocol: 'unix',
|
|
128
|
-
pathname: addr.path,
|
|
129
|
-
})
|
|
130
|
-
: url.format({
|
|
131
|
-
protocol: addr.proto,
|
|
132
|
-
hostname: addr.host,
|
|
133
|
-
port: addr.port,
|
|
134
|
-
pathname: '/',
|
|
135
|
-
})
|
|
136
|
-
}`;
|
|
137
|
-
logger.info(`http address ${addressServer}`);
|
|
138
|
-
logger.info(`version: ${version}`);
|
|
139
|
-
resolve();
|
|
140
|
-
})
|
|
141
|
-
.on('error', function (err): void {
|
|
142
|
-
reject(err);
|
|
143
|
-
process.exitCode = 1;
|
|
144
|
-
});
|
|
145
114
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
115
|
+
let app;
|
|
116
|
+
if (process.env.VERDACCIO_SERVER === 'fastify') {
|
|
117
|
+
app = await fastifyServer(config);
|
|
118
|
+
app.listen({ port: addr.port, host: addr.host }, (err) => {
|
|
119
|
+
if (err) {
|
|
120
|
+
reject(err);
|
|
121
|
+
} else {
|
|
122
|
+
resolve();
|
|
123
|
+
}
|
|
151
124
|
});
|
|
152
|
-
}
|
|
125
|
+
} else {
|
|
126
|
+
app = await server(config);
|
|
127
|
+
const serverFactory = createServerFactory(config, addr, app);
|
|
128
|
+
serverFactory
|
|
129
|
+
.listen(addr.port || addr.path, addr.host, (): void => {
|
|
130
|
+
// send a message for test
|
|
131
|
+
if (isFunction(process.send)) {
|
|
132
|
+
process.send({
|
|
133
|
+
verdaccio_started: true,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
const addressServer = `${
|
|
137
|
+
addr.path
|
|
138
|
+
? url.format({
|
|
139
|
+
protocol: 'unix',
|
|
140
|
+
pathname: addr.path,
|
|
141
|
+
})
|
|
142
|
+
: url.format({
|
|
143
|
+
protocol: addr.proto,
|
|
144
|
+
hostname: addr.host,
|
|
145
|
+
port: addr.port,
|
|
146
|
+
pathname: '/',
|
|
147
|
+
})
|
|
148
|
+
}`;
|
|
149
|
+
logger.info(`http address ${addressServer}`);
|
|
150
|
+
logger.info(`version: ${version}`);
|
|
151
|
+
resolve();
|
|
152
|
+
})
|
|
153
|
+
.on('error', function (err): void {
|
|
154
|
+
reject(err);
|
|
155
|
+
process.exitCode = 1;
|
|
156
|
+
});
|
|
157
|
+
function handleShutdownGracefully() {
|
|
158
|
+
logger.warn('received shutdown signal - closing server gracefully...');
|
|
159
|
+
serverFactory.close(() => {
|
|
160
|
+
logger.info('server closed.');
|
|
161
|
+
process.exit(0);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
153
164
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
165
|
+
for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) {
|
|
166
|
+
// Use once() so that receiving double signals exit the app.
|
|
167
|
+
process.once(signal, handleShutdownGracefully);
|
|
168
|
+
}
|
|
157
169
|
}
|
|
158
170
|
});
|
|
159
171
|
}
|
|
@@ -169,18 +181,18 @@ export async function initServer(
|
|
|
169
181
|
});
|
|
170
182
|
* @param config
|
|
171
183
|
*/
|
|
172
|
-
export async function runServer(config?: string |
|
|
173
|
-
let configurationParsed:
|
|
184
|
+
export async function runServer(config?: string | ConfigYaml): Promise<any> {
|
|
185
|
+
let configurationParsed: ConfigYaml;
|
|
174
186
|
if (config === undefined || typeof config === 'string') {
|
|
175
187
|
const configPathLocation = findConfigFile(config);
|
|
176
|
-
configurationParsed = parseConfigFile(configPathLocation)
|
|
188
|
+
configurationParsed = parseConfigFile(configPathLocation);
|
|
177
189
|
} else if (_.isObject(config)) {
|
|
178
190
|
configurationParsed = config;
|
|
179
191
|
} else {
|
|
180
192
|
throw new Error(API_ERROR.CONFIG_BAD_FORMAT);
|
|
181
193
|
}
|
|
182
194
|
|
|
183
|
-
setup(configurationParsed.log as
|
|
195
|
+
setup(configurationParsed.log as any);
|
|
184
196
|
displayExperimentsInfoBox(configurationParsed.flags);
|
|
185
197
|
// FIXME: get only the first match, the multiple address will be removed
|
|
186
198
|
const [addr] = getListListenAddresses(undefined, configurationParsed.listen);
|
package/test/run-server.spec.ts
CHANGED
|
@@ -11,12 +11,11 @@ describe('startServer via API', () => {
|
|
|
11
11
|
|
|
12
12
|
test('should fail on start with empty configuration', async () => {
|
|
13
13
|
// @ts-expect-error
|
|
14
|
-
await expect(runServer({})).rejects.toThrow(
|
|
15
|
-
'AssertionError [ERR_ASSERTION]: CONFIG: storage path not defined'
|
|
16
|
-
);
|
|
14
|
+
await expect(runServer({})).rejects.toThrow('config_path is required');
|
|
17
15
|
});
|
|
18
16
|
|
|
19
17
|
test('should fail on start with null as entry', async () => {
|
|
20
|
-
|
|
18
|
+
// @ts-expected-error
|
|
19
|
+
await expect(runServer(null)).rejects.toThrow();
|
|
21
20
|
});
|
|
22
21
|
});
|
package/tsconfig.json
CHANGED
|
@@ -13,9 +13,6 @@
|
|
|
13
13
|
{
|
|
14
14
|
"path": "../core/cli-ui"
|
|
15
15
|
},
|
|
16
|
-
{
|
|
17
|
-
"path": "../core/commons-api"
|
|
18
|
-
},
|
|
19
16
|
{
|
|
20
17
|
"path": "../logger"
|
|
21
18
|
},
|
|
@@ -23,7 +20,10 @@
|
|
|
23
20
|
"path": "../mock"
|
|
24
21
|
},
|
|
25
22
|
{
|
|
26
|
-
"path": "../server"
|
|
23
|
+
"path": "../server/express"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"path": "../server/fastify"
|
|
27
27
|
}
|
|
28
28
|
]
|
|
29
29
|
}
|