@underpostnet/underpost 2.98.3 → 2.99.1

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.
Files changed (42) hide show
  1. package/.env.development +1 -0
  2. package/.env.production +1 -0
  3. package/.env.test +1 -0
  4. package/README.md +2 -3
  5. package/bin/deploy.js +1 -1
  6. package/cli.md +113 -110
  7. package/manifests/deployment/dd-default-development/deployment.yaml +2 -2
  8. package/manifests/deployment/dd-test-development/deployment.yaml +4 -4
  9. package/package.json +1 -2
  10. package/src/api/user/user.router.js +7 -40
  11. package/src/cli/baremetal.js +67 -71
  12. package/src/cli/cloud-init.js +11 -12
  13. package/src/cli/cluster.js +22 -24
  14. package/src/cli/db.js +43 -50
  15. package/src/cli/deploy.js +163 -61
  16. package/src/cli/env.js +20 -5
  17. package/src/cli/fs.js +19 -21
  18. package/src/cli/index.js +38 -32
  19. package/src/cli/lxd.js +5 -5
  20. package/src/cli/monitor.js +83 -88
  21. package/src/cli/repository.js +7 -6
  22. package/src/cli/run.js +498 -288
  23. package/src/cli/secrets.js +3 -3
  24. package/src/cli/ssh.js +80 -32
  25. package/src/cli/static.js +1 -1
  26. package/src/cli/test.js +6 -7
  27. package/src/index.js +49 -32
  28. package/src/runtime/express/Express.js +7 -6
  29. package/src/server/auth.js +6 -1
  30. package/src/server/backup.js +11 -1
  31. package/src/server/conf.js +4 -4
  32. package/src/{cli → server}/cron.js +56 -29
  33. package/src/server/dns.js +39 -31
  34. package/src/server/peer.js +2 -2
  35. package/src/server/process.js +2 -2
  36. package/src/server/proxy.js +8 -7
  37. package/src/server/runtime.js +4 -7
  38. package/src/server/start.js +28 -15
  39. package/src/ws/IoServer.js +2 -3
  40. package/scripts/ssh-cluster-info.sh +0 -15
  41. package/src/cli/script.js +0 -85
  42. package/src/monitor.js +0 -34
@@ -7,7 +7,7 @@
7
7
  import dotenv from 'dotenv';
8
8
  import { shellExec } from '../server/process.js';
9
9
  import fs from 'fs-extra';
10
- import UnderpostRootEnv from './env.js';
10
+ import Underpost from '../index.js';
11
11
 
12
12
  dotenv.config();
13
13
 
@@ -41,7 +41,7 @@ class UnderpostSecret {
41
41
  createFromEnvFile(envPath) {
42
42
  const envObj = dotenv.parse(fs.readFileSync(envPath, 'utf8'));
43
43
  for (const key of Object.keys(envObj)) {
44
- UnderpostSecret.API.docker.set(key, envObj[key]);
44
+ Underpost.secret.docker.set(key, envObj[key]);
45
45
  }
46
46
  },
47
47
  set(key, value) {
@@ -61,7 +61,7 @@ class UnderpostSecret {
61
61
  createFromEnvFile(envPath) {
62
62
  const envObj = dotenv.parse(fs.readFileSync(envPath, 'utf8'));
63
63
  for (const key of Object.keys(envObj)) {
64
- UnderpostRootEnv.API.set(key, envObj[key]);
64
+ Underpost.env.set(key, envObj[key]);
65
65
  }
66
66
  },
67
67
  },
package/src/cli/ssh.js CHANGED
@@ -5,11 +5,10 @@
5
5
  */
6
6
 
7
7
  import { generateRandomPasswordSelection } from '../client/components/core/CommonJs.js';
8
- import Dns from '../server/dns.js';
9
8
  import { pbcopy, shellExec } from '../server/process.js';
10
9
  import { loggerFactory } from '../server/logger.js';
11
10
  import fs from 'fs-extra';
12
- import UnderpostRootEnv from './env.js';
11
+ import Underpost from '../index.js';
13
12
 
14
13
  const logger = loggerFactory(import.meta);
15
14
 
@@ -252,17 +251,17 @@ EOF`);
252
251
 
253
252
  // Set defaults
254
253
  if (!options.user) options.user = 'root';
255
- if (!options.host) options.host = await Dns.getPublicIp();
254
+ if (!options.host) options.host = await Underpost.dns.getPublicIp();
256
255
  if (!options.password) options.password = options.disablePassword ? '' : generateRandomPasswordSelection(16);
257
256
  if (!options.groups) options.groups = 'wheel';
258
257
  if (!options.port) options.port = 22; // Handle connect uri
259
258
 
260
- const userHome = UnderpostSSH.API.getUserHome(options.user);
259
+ const userHome = Underpost.ssh.getUserHome(options.user);
261
260
  options.userHome = userHome;
262
261
 
263
262
  // Load config and override password and host if user exists in config
264
263
  if (options.deployId) {
265
- const config = UnderpostSSH.API.loadConfigNode(options.deployId);
264
+ const config = Underpost.ssh.loadConfigNode(options.deployId);
266
265
  confNode = config.confNode;
267
266
  confNodePath = config.confNodePath;
268
267
 
@@ -335,7 +334,7 @@ EOF`);
335
334
  // Remove the private key copy folder and update config only if deployId is provided
336
335
  if (options.deployId) {
337
336
  if (!confNode) {
338
- const config = UnderpostSSH.API.loadConfigNode(options.deployId);
337
+ const config = Underpost.ssh.loadConfigNode(options.deployId);
339
338
  confNode = config.confNode;
340
339
  confNodePath = config.confNodePath;
341
340
  }
@@ -347,7 +346,7 @@ EOF`);
347
346
  }
348
347
 
349
348
  delete confNode.users[options.user];
350
- UnderpostSSH.API.saveConfigNode(confNodePath, confNode);
349
+ Underpost.ssh.saveConfigNode(confNodePath, confNode);
351
350
  }
352
351
 
353
352
  logger.info(`User removed`);
@@ -362,7 +361,7 @@ EOF`);
362
361
  // If deployId is provided, check for existing config and backup keys
363
362
  if (options.deployId) {
364
363
  if (!confNode) {
365
- const config = UnderpostSSH.API.loadConfigNode(options.deployId);
364
+ const config = Underpost.ssh.loadConfigNode(options.deployId);
366
365
  confNode = config.confNode;
367
366
  confNodePath = config.confNodePath;
368
367
  }
@@ -378,14 +377,14 @@ EOF`);
378
377
  logger.info(`User ${options.user} already exists in config. Importing existing keys...`);
379
378
 
380
379
  // Create system user if it doesn't exist
381
- const userExists = UnderpostSSH.API.checkUserExists(options.user);
380
+ const userExists = Underpost.ssh.checkUserExists(options.user);
382
381
  if (!userExists) {
383
- UnderpostSSH.API.createSystemUser(options.user, options.password, options.groups);
382
+ Underpost.ssh.createSystemUser(options.user, options.password, options.groups);
384
383
  }
385
384
 
386
- const userHome = UnderpostSSH.API.getUserHome(options.user);
385
+ const userHome = Underpost.ssh.getUserHome(options.user);
387
386
  const sshDir = `${userHome}/.ssh`;
388
- UnderpostSSH.API.ensureSSHDirectory(sshDir);
387
+ Underpost.ssh.ensureSSHDirectory(sshDir);
389
388
 
390
389
  const userKeyPath = `${sshDir}/id_rsa`;
391
390
  const userPubKeyPath = `${sshDir}/id_rsa.pub`;
@@ -394,10 +393,10 @@ EOF`);
394
393
  fs.copyFileSync(privateKeyPath, userKeyPath);
395
394
  fs.copyFileSync(publicKeyPath, userPubKeyPath);
396
395
 
397
- UnderpostSSH.API.configureAuthorizedKeys(sshDir, userPubKeyPath, options.disablePassword);
398
- UnderpostSSH.API.configureSudoAccess(options.user, options.password, options.disablePassword);
399
- UnderpostSSH.API.configureKnownHosts(sshDir, options.port, options.host);
400
- UnderpostSSH.API.setSSHFilePermissions(sshDir, options.user, userKeyPath, userPubKeyPath);
396
+ Underpost.ssh.configureAuthorizedKeys(sshDir, userPubKeyPath, options.disablePassword);
397
+ Underpost.ssh.configureSudoAccess(options.user, options.password, options.disablePassword);
398
+ Underpost.ssh.configureKnownHosts(sshDir, options.port, options.host);
399
+ Underpost.ssh.setSSHFilePermissions(sshDir, options.user, userKeyPath, userPubKeyPath);
401
400
 
402
401
  logger.info(`Keys imported from ${privateCopyDir} to ${sshDir}`);
403
402
  logger.info(`User added with existing keys`);
@@ -406,11 +405,11 @@ EOF`);
406
405
  }
407
406
 
408
407
  // New user or no existing keys - create new user and generate keys
409
- UnderpostSSH.API.createSystemUser(options.user, options.password, options.groups);
408
+ Underpost.ssh.createSystemUser(options.user, options.password, options.groups);
410
409
 
411
- const userHome = UnderpostSSH.API.getUserHome(options.user);
410
+ const userHome = Underpost.ssh.getUserHome(options.user);
412
411
  const sshDir = `${userHome}/.ssh`;
413
- UnderpostSSH.API.ensureSSHDirectory(sshDir);
412
+ Underpost.ssh.ensureSSHDirectory(sshDir);
414
413
 
415
414
  const keyPath = `${sshDir}/id_rsa`;
416
415
  const pubKeyPath = `${sshDir}/id_rsa.pub`;
@@ -421,10 +420,10 @@ EOF`);
421
420
  );
422
421
  }
423
422
 
424
- UnderpostSSH.API.configureAuthorizedKeys(sshDir, pubKeyPath, options.disablePassword);
425
- UnderpostSSH.API.configureSudoAccess(options.user, options.password, options.disablePassword);
426
- UnderpostSSH.API.configureKnownHosts(sshDir, options.port, options.host);
427
- UnderpostSSH.API.setSSHFilePermissions(sshDir, options.user, keyPath, pubKeyPath);
423
+ Underpost.ssh.configureAuthorizedKeys(sshDir, pubKeyPath, options.disablePassword);
424
+ Underpost.ssh.configureSudoAccess(options.user, options.password, options.disablePassword);
425
+ Underpost.ssh.configureKnownHosts(sshDir, options.port, options.host);
426
+ Underpost.ssh.setSSHFilePermissions(sshDir, options.user, keyPath, pubKeyPath);
428
427
 
429
428
  // Save a copy of the keys to the private folder only if deployId is provided
430
429
  if (options.deployId) {
@@ -447,7 +446,7 @@ EOF`);
447
446
  privateKeyCopyPath,
448
447
  publicKeyCopyPath,
449
448
  };
450
- UnderpostSSH.API.saveConfigNode(confNodePath, confNode);
449
+ Underpost.ssh.saveConfigNode(confNodePath, confNode);
451
450
  }
452
451
 
453
452
  logger.info(`User added`);
@@ -457,7 +456,7 @@ EOF`);
457
456
  // Handle config user listing (only with deployId)
458
457
  if (options.deployId) {
459
458
  if (!confNode) {
460
- const config = UnderpostSSH.API.loadConfigNode(options.deployId);
459
+ const config = Underpost.ssh.loadConfigNode(options.deployId);
461
460
  confNode = config.confNode;
462
461
  confNodePath = config.confNodePath;
463
462
  }
@@ -472,7 +471,7 @@ EOF`);
472
471
 
473
472
  // Handle generate root keys
474
473
  if (options.generate)
475
- UnderpostSSH.API.generateKeys({ user: options.user, password: options.password, host: options.host });
474
+ Underpost.ssh.generateKeys({ user: options.user, password: options.password, host: options.host });
476
475
 
477
476
  // Handle list operations
478
477
  if (options.keysList) shellExec(`cat ${userHome}/.ssh/authorized_keys`);
@@ -489,14 +488,63 @@ EOF`);
489
488
 
490
489
  // Handle start server
491
490
  if (options.start) {
492
- UnderpostSSH.API.chmod({ user: options.user });
493
- UnderpostSSH.API.initService({ port: options.port });
491
+ Underpost.ssh.chmod({ user: options.user });
492
+ Underpost.ssh.initService({ port: options.port });
494
493
  }
495
494
 
496
495
  // Handle status server
497
496
  if (options.status) shellExec('service sshd status');
498
497
  },
499
498
 
499
+ /**
500
+ * Generic SSH remote command runner that centralizes SSH execution logic.
501
+ * Executes arbitrary shell commands on a remote server via SSH with proper credential handling.
502
+ * @async
503
+ * @function sshRemoteRunner
504
+ * @param {string} remoteCommand - The command to execute on the remote server
505
+ * @param {Object} options - Configuration options for SSH execution
506
+ * @param {string} [options.deployId] - Deployment ID for credential lookup
507
+ * @param {string} [options.user] - SSH user for credential lookup
508
+ * @param {boolean} [options.dev=false] - Development mode flag
509
+ * @param {string} [options.cd='/home/dd/engine'] - Working directory on remote server
510
+ * @param {boolean} [options.useSudo=true] - Whether to use sudo for command execution
511
+ * @param {boolean} [options.remote=true] - Whether to execute as remote command (if false, runs locally)
512
+ * @returns {Promise<string>} Output from the shell execution
513
+ * @memberof UnderpostSSH
514
+ */
515
+ sshRemoteRunner: async (remoteCommand, options = {}) => {
516
+ const { deployId = '', user = '', dev = false, cd = '/home/dd/engine', useSudo = true, remote = true } = options;
517
+
518
+ // If not executing remotely, just run locally
519
+ if (!remote) {
520
+ return shellExec(remoteCommand);
521
+ }
522
+
523
+ // Set up SSH credentials from config
524
+ if (deployId && user) {
525
+ await Underpost.ssh.setDefautlSshCredentials({ deployId, user });
526
+ }
527
+
528
+ // Build the complete SSH command
529
+ const sshScript = `#!/usr/bin/env bash
530
+ set -euo pipefail
531
+
532
+ REMOTE_USER=$(node bin config get --plain DEFAULT_SSH_USER)
533
+ REMOTE_HOST=$(node bin config get --plain DEFAULT_SSH_HOST)
534
+ REMOTE_PORT=$(node bin config get --plain DEFAULT_SSH_PORT)
535
+ SSH_KEY=$(node bin config get --plain DEFAULT_SSH_KEY_PATH)
536
+
537
+ chmod 600 "$SSH_KEY"
538
+
539
+ ssh -i "$SSH_KEY" -o BatchMode=yes "$REMOTE_USER@$REMOTE_HOST" -p $REMOTE_PORT sh <<EOF
540
+ ${cd ? `cd ${cd}` : ''}
541
+ ${useSudo ? `sudo -n -- /bin/bash -lc "${remoteCommand}"` : remoteCommand}
542
+ EOF
543
+ `;
544
+
545
+ return shellExec(sshScript, { stdout: true });
546
+ },
547
+
500
548
  /**
501
549
  * Loads saved SSH credentials from config and sets them in the UnderpostRootEnv API.
502
550
  * @async
@@ -512,10 +560,10 @@ EOF`);
512
560
  if (fs.existsSync(confNodePath)) {
513
561
  const { users } = JSON.parse(fs.readFileSync(confNodePath, 'utf8'));
514
562
  const { user, host, keyPath, port } = users[options.user];
515
- UnderpostRootEnv.API.set('DEFAULT_SSH_USER', user);
516
- UnderpostRootEnv.API.set('DEFAULT_SSH_HOST', host);
517
- UnderpostRootEnv.API.set('DEFAULT_SSH_KEY_PATH', keyPath);
518
- UnderpostRootEnv.API.set('DEFAULT_SSH_PORT', port);
563
+ Underpost.env.set('DEFAULT_SSH_USER', user);
564
+ Underpost.env.set('DEFAULT_SSH_HOST', host);
565
+ Underpost.env.set('DEFAULT_SSH_KEY_PATH', keyPath);
566
+ Underpost.env.set('DEFAULT_SSH_PORT', port);
519
567
  } else logger.warn(`No SSH config found at ${confNodePath}`);
520
568
  },
521
569
 
package/src/cli/static.js CHANGED
@@ -412,7 +412,7 @@ class UnderpostStatic {
412
412
  // Handle config template generation
413
413
  if (options.generateConfig) {
414
414
  const configPath = typeof options.generateConfig === 'string' ? options.generateConfig : './static-config.json';
415
- return UnderpostStatic.API.generateConfigTemplate(configPath);
415
+ return Underpost.static.generateConfigTemplate(configPath);
416
416
  }
417
417
 
418
418
  // Parse comma-separated options
package/src/cli/test.js CHANGED
@@ -9,8 +9,7 @@ import { MariaDB } from '../db/mariadb/MariaDB.js';
9
9
  import { getNpmRootPath } from '../server/conf.js';
10
10
  import { actionInitLog, loggerFactory, setUpInfo } from '../server/logger.js';
11
11
  import { pbcopy, shellExec } from '../server/process.js';
12
- import UnderpostDeploy from './deploy.js';
13
-
12
+ import Underpost from '../index.js';
14
13
  const logger = loggerFactory(import.meta);
15
14
 
16
15
  /**
@@ -67,10 +66,10 @@ class UnderpostTest {
67
66
  options.podStatus &&
68
67
  typeof options.podStatus === 'string'
69
68
  )
70
- return await UnderpostTest.API.statusMonitor(options.podName, options.podStatus, options.kindType);
69
+ return await Underpost.test.statusMonitor(options.podName, options.podStatus, options.kindType);
71
70
 
72
71
  if (options.sh === true || options.logs === true) {
73
- const [pod] = UnderpostDeploy.API.get(deployList);
72
+ const [pod] = Underpost.deploy.get(deployList);
74
73
  if (pod) {
75
74
  if (options.sh) return pbcopy(`sudo kubectl exec -it ${pod.NAME} -- sh`);
76
75
  if (options.logs) return shellExec(`sudo kubectl logs -f ${pod.NAME}`);
@@ -104,7 +103,7 @@ class UnderpostTest {
104
103
  break;
105
104
  }
106
105
  else {
107
- const pods = UnderpostDeploy.API.get(deployId);
106
+ const pods = Underpost.deploy.get(deployId);
108
107
  if (pods.length > 0)
109
108
  for (const deployData of pods) {
110
109
  const { NAME } = deployData;
@@ -115,7 +114,7 @@ class UnderpostTest {
115
114
  else logger.warn(`Couldn't find pods in deployment`, { deployId });
116
115
  }
117
116
  }
118
- } else return UnderpostTest.API.run();
117
+ } else return Underpost.test.run();
119
118
  },
120
119
  /**
121
120
  * @method statusMonitor
@@ -134,7 +133,7 @@ class UnderpostTest {
134
133
  logger.info(`Loading instance`, { podName, status, kindType, deltaMs, maxAttempts });
135
134
  const _monitor = async () => {
136
135
  await timer(deltaMs);
137
- const pods = UnderpostDeploy.API.get(podName, kindType);
136
+ const pods = Underpost.deploy.get(podName, kindType);
138
137
  let result = pods.find((p) => p.STATUS === status || (status === 'Running' && p.STATUS === 'Completed'));
139
138
  logger.info(
140
139
  `Testing pod ${podName}... ${result ? 1 : 0}/1 - elapsed time ${deltaMs * (index + 1)}s - attempt ${
package/src/index.js CHANGED
@@ -7,7 +7,6 @@
7
7
  import UnderpostBaremetal from './cli/baremetal.js';
8
8
  import UnderpostCloudInit from './cli/cloud-init.js';
9
9
  import UnderpostCluster from './cli/cluster.js';
10
- import UnderpostCron from './cli/cron.js';
11
10
  import UnderpostDB from './cli/db.js';
12
11
  import UnderpostDeploy from './cli/deploy.js';
13
12
  import UnderpostRootEnv from './cli/env.js';
@@ -17,11 +16,14 @@ import UnderpostLxd from './cli/lxd.js';
17
16
  import UnderpostMonitor from './cli/monitor.js';
18
17
  import UnderpostRepository from './cli/repository.js';
19
18
  import UnderpostRun from './cli/run.js';
20
- import UnderpostScript from './cli/script.js';
21
19
  import UnderpostSecret from './cli/secrets.js';
22
20
  import UnderpostSSH from './cli/ssh.js';
23
21
  import UnderpostStatic from './cli/static.js';
24
22
  import UnderpostTest from './cli/test.js';
23
+
24
+ import UnderpostDns from './server/dns.js';
25
+ import UnderpostBackup from './server/backup.js';
26
+ import UnderpostCron from './server/cron.js';
25
27
  import UnderpostStartUp from './server/start.js';
26
28
 
27
29
  /**
@@ -36,7 +38,7 @@ class Underpost {
36
38
  * @type {String}
37
39
  * @memberof Underpost
38
40
  */
39
- static version = 'v2.98.3';
41
+ static version = 'v2.99.1';
40
42
  /**
41
43
  * Repository cli API
42
44
  * @static
@@ -64,15 +66,7 @@ class Underpost {
64
66
  static get test() {
65
67
  return UnderpostTest.API;
66
68
  }
67
- /**
68
- * Underpost Start Up cli API
69
- * @static
70
- * @type {UnderpostStartUp.API}
71
- * @memberof Underpost
72
- */
73
- static get start() {
74
- return UnderpostStartUp.API;
75
- }
69
+
76
70
  /**
77
71
  * Static cli API
78
72
  * @static
@@ -110,15 +104,6 @@ class Underpost {
110
104
  static get secret() {
111
105
  return UnderpostSecret.API;
112
106
  }
113
- /**
114
- * Scripts cli API
115
- * @static
116
- * @type {UnderpostScript.API}
117
- * @memberof Underpost
118
- */
119
- static get script() {
120
- return UnderpostScript.API;
121
- }
122
107
  /**
123
108
  * Database cli API
124
109
  * @static
@@ -137,15 +122,6 @@ class Underpost {
137
122
  static get deploy() {
138
123
  return UnderpostDeploy.API;
139
124
  }
140
- /**
141
- * Cron cli API
142
- * @static
143
- * @type {UnderpostCron.API}
144
- * @memberof Underpost
145
- */
146
- static get cron() {
147
- return UnderpostCron.API;
148
- }
149
125
  /**
150
126
  * File Storage cli API
151
127
  * @static
@@ -212,6 +188,46 @@ class Underpost {
212
188
  static get baremetal() {
213
189
  return UnderpostBaremetal.API;
214
190
  }
191
+
192
+ /**
193
+ * Dns cli API
194
+ * @static
195
+ * @type {UnderpostDns.API}
196
+ * @memberof Underpost
197
+ */
198
+ static get dns() {
199
+ return UnderpostDns.API;
200
+ }
201
+
202
+ /**
203
+ * BackUp cli API
204
+ * @static
205
+ * @type {UnderpostBackup.API}
206
+ * @memberof Underpost
207
+ */
208
+ static get backup() {
209
+ return UnderpostBackup.API;
210
+ }
211
+
212
+ /**
213
+ * Cron cli API
214
+ * @static
215
+ * @type {UnderpostCron.API}
216
+ * @memberof Underpost
217
+ */
218
+ static get cron() {
219
+ return UnderpostCron.API;
220
+ }
221
+
222
+ /**
223
+ * Start Up cli API
224
+ * @static
225
+ * @type {UnderpostStartUp.API}
226
+ * @memberof Underpost
227
+ */
228
+ static get start() {
229
+ return UnderpostStartUp.API;
230
+ }
215
231
  }
216
232
 
217
233
  const up = Underpost;
@@ -225,7 +241,6 @@ export {
225
241
  UnderpostBaremetal,
226
242
  UnderpostCloudInit,
227
243
  UnderpostCluster,
228
- UnderpostCron,
229
244
  UnderpostDB,
230
245
  UnderpostDeploy,
231
246
  UnderpostRootEnv,
@@ -236,10 +251,12 @@ export {
236
251
  UnderpostMonitor,
237
252
  UnderpostRepository,
238
253
  UnderpostRun,
239
- UnderpostScript,
240
254
  UnderpostSecret,
241
255
  UnderpostSSH,
242
256
  UnderpostTest,
257
+ UnderpostDns,
258
+ UnderpostBackup,
259
+ UnderpostCron,
243
260
  UnderpostStartUp,
244
261
  };
245
262
 
@@ -12,7 +12,6 @@ import swaggerUi from 'swagger-ui-express';
12
12
  import compression from 'compression';
13
13
  import { createServer } from 'http';
14
14
 
15
- import UnderpostStartUp from '../../server/start.js';
16
15
  import { loggerFactory, loggerMiddleware } from '../../server/logger.js';
17
16
  import { getCapVariableName, newInstance } from '../../client/components/core/CommonJs.js';
18
17
  import { MailerProvider } from '../../mailer/MailerProvider.js';
@@ -25,6 +24,8 @@ import { TLS } from '../../server/tls.js';
25
24
  import { shellExec } from '../../server/process.js';
26
25
  import { devProxyHostFactory, isDevProxyContext, isTlsDevProxy } from '../../server/conf.js';
27
26
 
27
+ import Underpost from '../../index.js';
28
+
28
29
  const logger = loggerFactory(import.meta);
29
30
 
30
31
  /**
@@ -143,7 +144,7 @@ class ExpressService {
143
144
  }
144
145
  return next();
145
146
  });
146
- await UnderpostStartUp.API.listenPortController(app, port, runningData);
147
+ await Underpost.start.listenPortController(app, port, runningData);
147
148
  return { portsUsed };
148
149
  }
149
150
 
@@ -214,7 +215,7 @@ class ExpressService {
214
215
  const { options, meta, ioServer } = await createIoServer(server, { host, path, db, port, origins });
215
216
 
216
217
  // Listen on the main port for the WS server
217
- await UnderpostStartUp.API.listenPortController(ioServer, port, {
218
+ await Underpost.start.listenPortController(ioServer, port, {
218
219
  runtime: 'nodejs',
219
220
  client: null,
220
221
  host,
@@ -232,7 +233,7 @@ class ExpressService {
232
233
  origins,
233
234
  path,
234
235
  });
235
- await UnderpostStartUp.API.listenPortController(peerServer, peerPort, {
236
+ await Underpost.start.listenPortController(peerServer, peerPort, {
236
237
  runtime: 'nodejs',
237
238
  client: null,
238
239
  host,
@@ -250,8 +251,8 @@ class ExpressService {
250
251
  if (useLocalSsl && process.env.NODE_ENV === 'development') {
251
252
  if (!TLS.validateSecureContext()) shellExec(`node bin/deploy tls`);
252
253
  const { ServerSSL } = await TLS.createSslServer(app);
253
- await UnderpostStartUp.API.listenPortController(ServerSSL, port, runningData);
254
- } else await UnderpostStartUp.API.listenPortController(server, port, runningData);
254
+ await Underpost.start.listenPortController(ServerSSL, port, runningData);
255
+ } else await Underpost.start.listenPortController(server, port, runningData);
255
256
 
256
257
  return { portsUsed };
257
258
  }
@@ -349,7 +349,12 @@ const cookieOptionsFactory = (req, host) => {
349
349
  secure,
350
350
  sameSite,
351
351
  path: '/',
352
- domain: process.env.NODE_ENV === 'production' || isDevProxyContext() ? host : 'localhost',
352
+ domain:
353
+ process.env.NODE_ENV === 'production' ||
354
+ isDevProxyContext() ||
355
+ (req.headers.host && req.headers.host.toLocaleLowerCase().match(host))
356
+ ? host
357
+ : 'localhost',
353
358
  maxAge,
354
359
  };
355
360
 
@@ -43,5 +43,15 @@ class BackUp {
43
43
  }
44
44
  };
45
45
  }
46
+ /**
47
+ * Main UnderpostBakcup class for backup operations.
48
+ * @class UnderpostBakcup
49
+ * @memberof UnderpostBakcup
50
+ */
51
+ class UnderpostBakcUp {
52
+ static API = BackUp;
53
+ }
54
+
55
+ export default UnderpostBakcUp;
46
56
 
47
- export default BackUp;
57
+ export { BackUp, UnderpostBakcUp };
@@ -22,7 +22,7 @@ import { loggerFactory } from './logger.js';
22
22
  import { shellExec } from './process.js';
23
23
  import { DefaultConf } from '../../conf.js';
24
24
  import splitFile from 'split-file';
25
- import UnderpostRootEnv from '../cli/env.js';
25
+ import Underpost from '../index.js';
26
26
 
27
27
  colors.enable();
28
28
 
@@ -59,7 +59,7 @@ const Config = {
59
59
  if (!subConf && process.argv[3] && typeof process.argv[3] === 'string') subConf = process.argv[3];
60
60
  if (!fs.existsSync(`./tmp`)) fs.mkdirSync(`./tmp`);
61
61
  if (!fs.existsSync(`./conf`)) fs.mkdirSync(`./conf`);
62
- UnderpostRootEnv.API.set('await-deploy', new Date().toISOString());
62
+ Underpost.env.set('await-deploy', new Date().toISOString());
63
63
  if (deployContext.startsWith('dd-')) loadConf(deployContext, subConf);
64
64
  if (deployContext === 'proxy') await Config.buildProxy(deployList, subConf);
65
65
  },
@@ -1050,9 +1050,9 @@ const validateTemplatePath = (absolutePath = '') => {
1050
1050
  * @memberof ServerConfBuilder
1051
1051
  */
1052
1052
  const awaitDeployMonitor = async (init = false, deltaMs = 1000) => {
1053
- if (init) UnderpostRootEnv.API.set('await-deploy', new Date().toISOString());
1053
+ if (init) Underpost.env.set('await-deploy', new Date().toISOString());
1054
1054
  await timer(deltaMs);
1055
- if (UnderpostRootEnv.API.get('await-deploy')) return await awaitDeployMonitor();
1055
+ if (Underpost.env.get('await-deploy')) return await awaitDeployMonitor();
1056
1056
  };
1057
1057
 
1058
1058
  /**