1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | Object.defineProperty(exports, "__esModule", { value: true });
|
7 | const fs_1 = require("fs");
|
8 | const path = require("path");
|
9 | const FIXTURES = path.resolve(__dirname, '../fixtures');
|
10 | const DUMMY_TLS_CONFIG = {
|
11 | key: fs_1.readFileSync(path.join(FIXTURES, 'key.pem')),
|
12 | cert: fs_1.readFileSync(path.join(FIXTURES, 'cert.pem')),
|
13 | };
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | function givenHttpServerConfig(customConfig) {
|
24 | const defaults = {
|
25 | host: '127.0.0.1',
|
26 | port: 0,
|
27 | protocol: undefined,
|
28 | };
|
29 | const config = Object.assign({}, defaults, customConfig);
|
30 | if (config.host === undefined)
|
31 | config.host = defaults.host;
|
32 | if (config.port === undefined)
|
33 | config.port = defaults.port;
|
34 | if (isHttpsConfig(config)) {
|
35 | setupTlsConfig(config);
|
36 | }
|
37 | return config;
|
38 | }
|
39 | exports.givenHttpServerConfig = givenHttpServerConfig;
|
40 | function setupTlsConfig(config) {
|
41 | if ('key' in config && 'cert' in config)
|
42 | return;
|
43 | if ('pfx' in config)
|
44 | return;
|
45 | Object.assign(config, DUMMY_TLS_CONFIG);
|
46 | }
|
47 | function isHttpsConfig(config) {
|
48 | return config && config.protocol === 'https';
|
49 | }
|
50 |
|
\ | No newline at end of file |