underpost 2.7.8 → 2.7.9

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 (57) hide show
  1. package/.github/workflows/ghpkg.yml +41 -1
  2. package/.github/workflows/publish.yml +17 -18
  3. package/.github/workflows/pwa-microservices-template.page.yml +54 -0
  4. package/.vscode/settings.json +6 -0
  5. package/CHANGELOG.md +64 -16
  6. package/bin/cron.js +47 -0
  7. package/bin/db.js +9 -1
  8. package/bin/deploy.js +194 -9
  9. package/bin/file.js +17 -1
  10. package/bin/index.js +1 -1
  11. package/bin/util.js +22 -0
  12. package/conf.js +18 -4
  13. package/docker-compose.yml +1 -1
  14. package/package.json +3 -3
  15. package/src/api/core/core.router.js +9 -9
  16. package/src/api/core/core.service.js +6 -4
  17. package/src/api/default/default.service.js +4 -4
  18. package/src/api/file/file.service.js +3 -3
  19. package/src/api/user/user.service.js +7 -7
  20. package/src/client/components/core/CssCore.js +30 -3
  21. package/src/client/components/core/Docs.js +110 -10
  22. package/src/client/components/core/Modal.js +224 -22
  23. package/src/client/components/core/Panel.js +1 -1
  24. package/src/client/components/core/PanelForm.js +2 -1
  25. package/src/client/components/core/Responsive.js +15 -0
  26. package/src/client/components/core/RichText.js +4 -2
  27. package/src/client/components/core/WebComponent.js +44 -0
  28. package/src/client/components/core/Worker.js +10 -12
  29. package/src/client/public/default/plantuml/client-conf.svg +1 -1
  30. package/src/client/public/default/plantuml/client-schema.svg +1 -1
  31. package/src/client/public/default/plantuml/cron-conf.svg +1 -1
  32. package/src/client/public/default/plantuml/cron-schema.svg +1 -1
  33. package/src/client/public/default/plantuml/server-conf.svg +1 -1
  34. package/src/client/public/default/plantuml/server-schema.svg +1 -1
  35. package/src/client/public/default/plantuml/ssr-conf.svg +1 -1
  36. package/src/client/public/default/plantuml/ssr-schema.svg +1 -1
  37. package/src/client/public/default/site.webmanifest +69 -0
  38. package/src/client/ssr/components/body/CacheControl.js +1 -1
  39. package/src/client/ssr/components/head/Production.js +1 -0
  40. package/src/client/ssr/components/head/Pwa.js +146 -0
  41. package/src/client/ssr/components/head/Seo.js +14 -0
  42. package/src/client/ssr/pages/maintenance.js +14 -0
  43. package/src/client/ssr/pages/offline.js +21 -0
  44. package/src/client/sw/default.sw.js +4 -2
  45. package/src/db/DataBaseProvider.js +12 -1
  46. package/src/db/mongo/MongooseDB.js +0 -1
  47. package/src/server/backup.js +82 -70
  48. package/src/server/client-build.js +23 -90
  49. package/src/server/conf.js +51 -5
  50. package/src/server/crypto.js +91 -0
  51. package/src/server/dns.js +42 -13
  52. package/src/server/network.js +94 -7
  53. package/src/server/proxy.js +27 -27
  54. package/src/server/runtime.js +3 -1
  55. package/src/client/ssr/offline/default.index.js +0 -31
  56. package/src/cron.js +0 -30
  57. package/src/server/cron.js +0 -35
@@ -9,7 +9,8 @@ import { loggerFactory, loggerMiddleware } from './logger.js';
9
9
  import { listenPortController, network } from './network.js';
10
10
  import { orderArrayFromAttrInt } from '../client/components/core/CommonJs.js';
11
11
  import { createSslServer, sslRedirectMiddleware } from './ssl.js';
12
- import { buildProxyRouter } from './conf.js';
12
+ import { buildProxyRouter, maintenanceMiddleware } from './conf.js';
13
+ import { getRootDirectory } from './process.js';
13
14
 
14
15
  dotenv.config();
15
16
 
@@ -25,6 +26,9 @@ const buildProxy = async () => {
25
26
  for (let port of Object.keys(proxyRouter)) {
26
27
  port = parseInt(port);
27
28
  const hosts = proxyRouter[port];
29
+ const proxyPath = '/';
30
+ const proxyHost = 'localhost';
31
+ const runningData = { host: proxyHost, path: proxyPath, client: null, runtime: 'nodejs', meta: import.meta };
28
32
  const app = express();
29
33
 
30
34
  // set logger
@@ -47,6 +51,7 @@ const buildProxy = async () => {
47
51
  onProxyReq: (proxyReq, req, res, options) => {
48
52
  // https://wtools.io/check-http-status-code
49
53
  // http://nexodev.org
54
+ maintenanceMiddleware(req, res, port, proxyRouter);
50
55
  sslRedirectMiddleware(req, res, port, proxyRouter);
51
56
  },
52
57
  pathRewrite: {
@@ -54,30 +59,27 @@ const buildProxy = async () => {
54
59
  // '^/target-path': '/',
55
60
  },
56
61
  };
57
-
58
- // build router
59
- Object.keys(hosts).map((hostKey) => {
60
- let { host, path, target, proxy, peer } = hosts[hostKey];
61
- if (process.env.NODE_ENV === 'development') host = `localhost`;
62
-
63
- if (!proxy.includes(port)) return;
64
- const absoluteHost = [80, 443].includes(port)
65
- ? `${host}${path === '/' ? '' : path}`
66
- : `${host}:${port}${path === '/' ? '' : path}`;
67
-
68
- if (!(absoluteHost in options.router)) options.router[absoluteHost] = target;
69
- });
70
- if (Object.keys(options.router).length === 0) continue;
71
-
72
- // order router
73
- const router = {};
74
- for (const absoluteHostKey of orderArrayFromAttrInt(Object.keys(options.router), 'length'))
75
- router[absoluteHostKey] = options.router[absoluteHostKey];
76
- options.router = router;
77
-
78
- // instance proxy server
79
- const proxyPath = '/';
80
- const proxyHost = 'localhost';
62
+ if (!process.argv.includes('maintenance')) {
63
+ // build router
64
+ Object.keys(hosts).map((hostKey) => {
65
+ let { host, path, target, proxy, peer } = hosts[hostKey];
66
+ if (process.env.NODE_ENV === 'development') host = `localhost`;
67
+
68
+ if (!proxy.includes(port)) return;
69
+ const absoluteHost = [80, 443].includes(port)
70
+ ? `${host}${path === '/' ? '' : path}`
71
+ : `${host}:${port}${path === '/' ? '' : path}`;
72
+
73
+ if (!(absoluteHost in options.router)) options.router[absoluteHost] = target;
74
+ });
75
+ if (Object.keys(options.router).length === 0) continue;
76
+
77
+ // order router
78
+ const router = {};
79
+ for (const absoluteHostKey of orderArrayFromAttrInt(Object.keys(options.router), 'length'))
80
+ router[absoluteHostKey] = options.router[absoluteHostKey];
81
+ options.router = router;
82
+ }
81
83
 
82
84
  const filter = false
83
85
  ? (pathname, req) => {
@@ -88,8 +90,6 @@ const buildProxy = async () => {
88
90
  app.use(proxyPath, createProxyMiddleware(filter, options));
89
91
  await network.port.portClean(port);
90
92
 
91
- const runningData = { host: proxyHost, path: proxyPath, client: null, runtime: 'nodejs', meta: import.meta };
92
-
93
93
  switch (process.env.NODE_ENV) {
94
94
  case 'production':
95
95
  switch (port) {
@@ -18,13 +18,14 @@ import { DataBaseProvider } from '../db/DataBaseProvider.js';
18
18
  import { createProxyMiddleware } from 'http-proxy-middleware';
19
19
  import { createPeerServer } from './peer.js';
20
20
  import { Lampp } from '../runtime/lampp/Lampp.js';
21
+ import { getDeployId } from './conf.js';
21
22
 
22
23
  dotenv.config();
23
24
 
24
25
  const logger = loggerFactory(import.meta);
25
26
 
26
27
  const buildRuntime = async () => {
27
- const deployId = `${process.argv[3] ? process.argv[3] : 'default'}`;
28
+ const deployId = getDeployId();
28
29
 
29
30
  const collectDefaultMetrics = promClient.collectDefaultMetrics;
30
31
  collectDefaultMetrics();
@@ -95,6 +96,7 @@ export PATH=$PATH:/opt/lampp/bin`,
95
96
  runtime,
96
97
  client,
97
98
  meta: import.meta,
99
+ apis,
98
100
  };
99
101
 
100
102
  let redirectUrl;
@@ -1,31 +0,0 @@
1
- import { htmls, loggerFactory } from '../common/SsrCore.js';
2
- import { Alert } from '../common/Alert.js';
3
- import { Translate } from '../common/Translate.js';
4
- import { Worker } from '../common/Worker.js';
5
- /*imports*/
6
-
7
- const logger = loggerFactory({ url: '/offline.js' });
8
-
9
- window.onload = () =>
10
- Worker.instance({
11
- render: async () => {
12
- window.ononline = async () => {
13
- location.href = '/';
14
- };
15
- window.onoffline = async () => {
16
- htmls(`.page-render`, html`${await Alert.noInternet({ Translate })}`);
17
- };
18
- try {
19
- if (navigator.onLine) {
20
- const maintenance = await fetch(location.origin + '/favicon.ico');
21
- if (maintenance.status !== 200) {
22
- htmls(`.page-render`, html`${await Alert.maintenance({ Translate })}`);
23
- } else window.ononline();
24
- }
25
- throw new Error(`no internet connection`);
26
- } catch (error) {
27
- logger.error(error);
28
- window.onoffline();
29
- }
30
- },
31
- });
package/src/cron.js DELETED
@@ -1,30 +0,0 @@
1
- 'use strict';
2
-
3
- // https://nodejs.org/api
4
- // https://expressjs.com/en/4x/api.html
5
-
6
- import dotenv from 'dotenv';
7
- import { loggerFactory } from './server/logger.js';
8
- import { Dns } from './server/dns.js';
9
- import { ProcessController } from './server/process.js';
10
- import { Config } from './server/conf.js';
11
- import { BackUpManagement } from './server/backup.js';
12
- import { CronManagement } from './server/cron.js';
13
-
14
- dotenv.config();
15
-
16
- await Config.build();
17
-
18
- const logger = loggerFactory(import.meta);
19
-
20
- await logger.setUpInfo();
21
-
22
- // every minutes
23
- CronManagement.add('ip', '* * * * *', await Dns.InitIpDaemon());
24
-
25
- // every day at 1 am
26
- CronManagement.add('backup', '0 1 * * *', await BackUpManagement.Init());
27
-
28
- await CronManagement.init();
29
-
30
- ProcessController.init(logger);
@@ -1,35 +0,0 @@
1
- import cron from 'node-cron';
2
- import { loggerFactory } from './logger.js';
3
-
4
- const logger = loggerFactory(import.meta);
5
-
6
- const CronManagement = {
7
- data: {},
8
- init: function () {
9
- // verify tokens
10
- // https://github.com/settings/tokens
11
- for (const cronKey of Object.keys(this.data)) {
12
- if (this.data[cronKey].valid) {
13
- this.data[cronKey].task.start();
14
- logger.info(`Cron task "${this.data[cronKey].name}" started`);
15
- } else {
16
- logger.error(
17
- `Invalid cron expression "${this.data[cronKey].expression}" for task "${this.data[cronKey].name}"`,
18
- );
19
- }
20
- }
21
- },
22
- add: function (name = 'task', expression = '* * * * *', callback = async () => null) {
23
- const args = { name, expression, valid: cron.validate(expression) };
24
- this.data[name] = {
25
- ...args,
26
- task: cron.schedule(expression, callback, {
27
- scheduled: false,
28
- timezone: process.env.TIME_ZONE || 'America/New_York',
29
- name,
30
- }),
31
- };
32
- },
33
- };
34
-
35
- export { CronManagement };