1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | exports.setupServer = void 0;
|
7 | const fs_extra_1 = require("fs-extra");
|
8 | const globby_1 = __importDefault(require("globby"));
|
9 | const path_1 = require("path");
|
10 | const environment_1 = require("./environment");
|
11 | async function setupServer(options) {
|
12 | var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
13 | const serverOptions = (_a = options.server) !== null && _a !== void 0 ? _a : {};
|
14 | let https;
|
15 | let cert;
|
16 | let privkey;
|
17 | if (!('https' in serverOptions)) {
|
18 |
|
19 | cert = (await globby_1.default(path_1.resolve(process.cwd(), './config/ssl/(certificate|cert).pem'))).pop();
|
20 | privkey = (await globby_1.default(path_1.resolve(process.cwd(), './config/ssl/(private-key|privkey).pem'))).pop();
|
21 | https = !!(cert && privkey);
|
22 | }
|
23 | else {
|
24 | https = (_b = serverOptions.https) !== null && _b !== void 0 ? _b : false;
|
25 | }
|
26 | const config = {
|
27 | host: (_c = serverOptions.host) !== null && _c !== void 0 ? _c : 'home.cowtech.it',
|
28 | port: (_d = serverOptions.port) !== null && _d !== void 0 ? _d : 4200,
|
29 | https,
|
30 | compress: (_e = serverOptions.compress) !== null && _e !== void 0 ? _e : true,
|
31 | historyApiFallback: (_f = serverOptions.history) !== null && _f !== void 0 ? _f : true,
|
32 | disableHostCheck: (_g = serverOptions.disableHostCheck) !== null && _g !== void 0 ? _g : true,
|
33 | inline: (_h = serverOptions.inline) !== null && _h !== void 0 ? _h : true,
|
34 | ...((_j = serverOptions.options) !== null && _j !== void 0 ? _j : {})
|
35 | };
|
36 | if (config.https) {
|
37 | config.https = {
|
38 | key: await fs_extra_1.readFile((_l = (_k = config.https) === null || _k === void 0 ? void 0 : _k.key) !== null && _l !== void 0 ? _l : privkey),
|
39 | cert: await fs_extra_1.readFile((_o = (_m = config.https) === null || _m === void 0 ? void 0 : _m.cert) !== null && _o !== void 0 ? _o : cert)
|
40 | };
|
41 | }
|
42 | return environment_1.runHook(config, serverOptions.afterHook);
|
43 | }
|
44 | exports.setupServer = setupServer;
|