underpost 2.7.1 → 2.7.3

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 (214) hide show
  1. package/.dockerignore +13 -13
  2. package/.env.development +7 -7
  3. package/.env.production +7 -7
  4. package/.env.test +7 -7
  5. package/.github/workflows/publish.yml +26 -0
  6. package/.github/workflows/test.yml +80 -0
  7. package/.nycrc +9 -9
  8. package/.prettierignore +12 -12
  9. package/.prettierrc +9 -9
  10. package/.vscode/extensions.json +72 -72
  11. package/.vscode/settings.json +100 -99
  12. package/Dockerfile +89 -89
  13. package/LICENSE +21 -21
  14. package/README.md +96 -96
  15. package/bin/db.js +172 -119
  16. package/bin/deploy.js +607 -661
  17. package/bin/file.js +93 -92
  18. package/bin/index.js +76 -53
  19. package/bin/ssl.js +55 -64
  20. package/bin/util.js +182 -182
  21. package/bin/vs.js +35 -35
  22. package/conf.js +251 -249
  23. package/docker-compose.yml +67 -67
  24. package/jsconfig.json +7 -7
  25. package/jsdoc.json +32 -32
  26. package/nodemon.json +6 -6
  27. package/package.json +137 -132
  28. package/prometheus.yml +36 -36
  29. package/setup.sh +24 -24
  30. package/src/api/core/core.controller.js +69 -69
  31. package/src/api/core/core.model.js +11 -11
  32. package/src/api/core/core.router.js +23 -23
  33. package/src/api/core/core.service.js +29 -29
  34. package/src/api/crypto/crypto.controller.js +51 -51
  35. package/src/api/crypto/crypto.model.js +23 -23
  36. package/src/api/crypto/crypto.router.js +20 -20
  37. package/src/api/crypto/crypto.service.js +64 -64
  38. package/src/api/default/default.controller.js +69 -69
  39. package/src/api/default/default.model.js +20 -20
  40. package/src/api/default/default.router.js +23 -23
  41. package/src/api/default/default.service.js +31 -31
  42. package/src/api/file/file.controller.js +53 -51
  43. package/src/api/file/file.model.js +19 -19
  44. package/src/api/file/file.router.js +21 -20
  45. package/src/api/file/file.service.js +76 -70
  46. package/src/api/instance/instance.controller.js +69 -69
  47. package/src/api/instance/instance.model.js +36 -36
  48. package/src/api/instance/instance.router.js +33 -33
  49. package/src/api/instance/instance.service.js +48 -48
  50. package/src/api/test/test.controller.js +59 -59
  51. package/src/api/test/test.model.js +14 -14
  52. package/src/api/test/test.router.js +21 -21
  53. package/src/api/test/test.service.js +35 -35
  54. package/src/api/user/user.build.js +16 -0
  55. package/src/api/user/user.controller.js +70 -70
  56. package/src/api/user/user.model.js +65 -65
  57. package/src/api/user/user.router.js +345 -345
  58. package/src/api/user/user.service.js +479 -479
  59. package/src/api.js +23 -23
  60. package/src/client/Default.index.js +40 -40
  61. package/src/client/components/core/Account.js +290 -290
  62. package/src/client/components/core/AgGrid.js +160 -160
  63. package/src/client/components/core/Auth.js +19 -19
  64. package/src/client/components/core/Badge.js +32 -32
  65. package/src/client/components/core/{BlockChain.js → Blockchain.js} +41 -41
  66. package/src/client/components/core/Blog.js +9 -9
  67. package/src/client/components/core/BtnIcon.js +101 -94
  68. package/src/client/components/core/CalendarCore.js +458 -319
  69. package/src/client/components/core/Chat.js +64 -64
  70. package/src/client/components/core/ColorPalette.js +5267 -5267
  71. package/src/client/components/core/CommonJs.js +735 -732
  72. package/src/client/components/core/Content.js +193 -49
  73. package/src/client/components/core/Css.js +1064 -1027
  74. package/src/client/components/core/CssCore.js +817 -796
  75. package/src/client/components/core/D3Chart.js +44 -44
  76. package/src/client/components/core/Docs.js +229 -229
  77. package/src/client/components/core/DropDown.js +164 -164
  78. package/src/client/components/core/EventsUI.js +46 -54
  79. package/src/client/components/core/FileExplorer.js +699 -624
  80. package/src/client/components/core/FullScreen.js +45 -45
  81. package/src/client/components/core/Input.js +346 -259
  82. package/src/client/components/core/JoyStick.js +77 -77
  83. package/src/client/components/core/Keyboard.js +73 -73
  84. package/src/client/components/core/LoadingAnimation.js +179 -157
  85. package/src/client/components/core/LogIn.js +187 -181
  86. package/src/client/components/core/LogOut.js +58 -52
  87. package/src/client/components/core/Logger.js +26 -26
  88. package/src/client/components/core/Modal.js +1612 -1596
  89. package/src/client/components/core/NotificationManager.js +84 -84
  90. package/src/client/components/core/Panel.js +613 -413
  91. package/src/client/components/core/PanelForm.js +468 -0
  92. package/src/client/components/core/Polyhedron.js +162 -162
  93. package/src/client/components/core/Recover.js +204 -204
  94. package/src/client/components/core/Responsive.js +53 -53
  95. package/src/client/components/core/RichText.js +51 -27
  96. package/src/client/components/core/Router.js +76 -77
  97. package/src/client/components/core/Scroll.js +34 -0
  98. package/src/client/components/core/SignUp.js +125 -125
  99. package/src/client/components/core/SocketIo.js +72 -72
  100. package/src/client/components/core/Stream.js +113 -113
  101. package/src/client/components/core/ToggleSwitch.js +87 -87
  102. package/src/client/components/core/ToolTip.js +26 -26
  103. package/src/client/components/core/Translate.js +437 -408
  104. package/src/client/components/core/Validator.js +100 -100
  105. package/src/client/components/core/VanillaJs.js +460 -457
  106. package/src/client/components/core/Wallet.js +106 -106
  107. package/src/client/components/core/Webhook.js +25 -25
  108. package/src/client/components/core/Worker.js +272 -272
  109. package/src/client/components/default/CommonDefault.js +29 -29
  110. package/src/client/components/default/CssDefault.js +13 -13
  111. package/src/client/components/default/ElementsDefault.js +38 -38
  112. package/src/client/components/default/LogInDefault.js +41 -41
  113. package/src/client/components/default/LogOutDefault.js +28 -28
  114. package/src/client/components/default/MenuDefault.js +389 -389
  115. package/src/client/components/default/RoutesDefault.js +48 -48
  116. package/src/client/components/default/SettingsDefault.js +16 -16
  117. package/src/client/components/default/SignUpDefault.js +9 -9
  118. package/src/client/components/default/SocketIoDefault.js +54 -54
  119. package/src/client/components/default/TranslateDefault.js +7 -7
  120. package/src/client/public/default/assets/mailer/api-user-check.png +0 -0
  121. package/src/client/public/default/assets/mailer/api-user-invalid-token.png +0 -0
  122. package/src/client/public/default/assets/mailer/api-user-recover.png +0 -0
  123. package/src/client/public/default/browserconfig.xml +11 -11
  124. package/src/client/public/default/manifest.webmanifest +68 -68
  125. package/src/client/public/default/plantuml/client-conf.svg +1 -0
  126. package/src/client/public/default/plantuml/client-schema.svg +1 -0
  127. package/src/client/public/default/plantuml/cron-conf.svg +1 -0
  128. package/src/client/public/default/plantuml/cron-schema.svg +1 -0
  129. package/src/client/public/default/plantuml/server-conf.svg +1 -0
  130. package/src/client/public/default/plantuml/server-schema.svg +1 -0
  131. package/src/client/public/default/plantuml/ssr-conf.svg +1 -0
  132. package/src/client/public/default/plantuml/ssr-schema.svg +1 -0
  133. package/src/client/public/default/sitemap +147 -147
  134. package/src/client/public/default/yandex-browser-manifest.json +8 -8
  135. package/src/client/public/doc/sitemap +147 -147
  136. package/src/client/public/test/sitemap +147 -147
  137. package/src/client/services/core/core.service.js +170 -152
  138. package/src/client/services/crypto/crypto.service.js +70 -70
  139. package/src/client/services/default/default.management.js +345 -345
  140. package/src/client/services/default/default.service.js +89 -89
  141. package/src/client/services/file/file.service.js +70 -70
  142. package/src/client/services/instance/instance.management.js +74 -74
  143. package/src/client/services/instance/instance.service.js +89 -89
  144. package/src/client/services/test/test.service.js +70 -70
  145. package/src/client/services/user/user.management.js +50 -50
  146. package/src/client/services/user/user.service.js +89 -89
  147. package/src/client/ssr/Render.js +16 -16
  148. package/src/client/ssr/body-components/CacheControl.js +114 -113
  149. package/src/client/ssr/body-components/DefaultSplashScreen.js +79 -79
  150. package/src/client/ssr/email-components/DefaultRecoverEmail.js +21 -21
  151. package/src/client/ssr/email-components/DefaultVerifyEmail.js +17 -17
  152. package/src/client/ssr/head-components/Css.js +241 -241
  153. package/src/client/ssr/head-components/DefaultScripts.js +3 -3
  154. package/src/client/ssr/head-components/Microdata.js +11 -11
  155. package/src/client/ssr/head-components/Production.js +1 -1
  156. package/src/client/ssr/head-components/PwaDefault.js +59 -59
  157. package/src/client/ssr/head-components/Seo.js +14 -14
  158. package/src/client/sw/default.sw.js +201 -201
  159. package/src/client/sw/template.sw.js +84 -84
  160. package/src/client.build.js +22 -22
  161. package/src/client.dev.js +21 -21
  162. package/src/cron.js +25 -25
  163. package/src/db/DataBaseProvider.js +34 -34
  164. package/src/db/mariadb/MariaDB.js +33 -33
  165. package/src/db/mongo/MongooseDB.js +137 -46
  166. package/src/dns.js +22 -22
  167. package/src/index.js +42 -29
  168. package/src/mailer/EmailRender.js +69 -69
  169. package/src/mailer/MailerProvider.js +96 -96
  170. package/src/proxy.js +22 -22
  171. package/src/runtime/lampp/Lampp.js +115 -44
  172. package/src/runtime/nginx/Nginx.js +3 -3
  173. package/src/runtime/xampp/Xampp.js +49 -49
  174. package/src/server/auth.js +235 -204
  175. package/src/server/backup.js +101 -94
  176. package/src/server/client-build-live.js +72 -72
  177. package/src/server/client-build.js +699 -699
  178. package/src/server/client-dev-server.js +60 -58
  179. package/src/server/client-formatted.js +48 -48
  180. package/src/server/client-icons.js +149 -150
  181. package/src/server/conf.js +860 -611
  182. package/src/server/dns.js +98 -98
  183. package/src/server/downloader.js +42 -42
  184. package/src/server/logger.js +190 -180
  185. package/src/server/network.js +122 -122
  186. package/src/server/peer.js +33 -33
  187. package/src/server/process.js +66 -66
  188. package/src/server/prompt-optimizer.js +28 -28
  189. package/src/server/proxy.js +118 -118
  190. package/src/server/runtime.js +444 -393
  191. package/src/server/ssl.js +120 -107
  192. package/src/server.js +25 -25
  193. package/src/ws/IoInterface.js +45 -45
  194. package/src/ws/IoServer.js +39 -39
  195. package/src/ws/core/channels/core.ws.chat.js +23 -23
  196. package/src/ws/core/channels/core.ws.mailer.js +35 -35
  197. package/src/ws/core/channels/core.ws.stream.js +31 -31
  198. package/src/ws/core/core.ws.connection.js +28 -28
  199. package/src/ws/core/core.ws.emit.js +14 -14
  200. package/src/ws/core/core.ws.server.js +24 -24
  201. package/src/ws/core/management/core.ws.chat.js +8 -8
  202. package/src/ws/core/management/core.ws.mailer.js +16 -16
  203. package/src/ws/core/management/core.ws.stream.js +8 -8
  204. package/src/ws/default/channels/default.ws.main.js +16 -16
  205. package/src/ws/default/default.ws.connection.js +22 -22
  206. package/src/ws/default/default.ws.emit.js +14 -14
  207. package/src/ws/default/default.ws.server.js +20 -20
  208. package/src/ws/default/management/default.ws.main.js +8 -8
  209. package/startup.js +11 -11
  210. package/supervisord-openssh-server.conf +4 -4
  211. package/test/api.test.js +60 -60
  212. package/bin/dns.js +0 -1
  213. package/bin/install.js +0 -357
  214. package/bin/shortcut.js +0 -44
@@ -1,180 +1,190 @@
1
- /**
2
- * Module for managing logger control and configuration
3
- * @module src/server/logger.js
4
- * @namespace Logger
5
- */
6
-
7
- 'use strict';
8
-
9
- import dotenv from 'dotenv';
10
- import winston from 'winston';
11
- import morgan from 'morgan';
12
- import colorize from 'json-colorizer';
13
- import colors from 'colors';
14
- import v8 from 'v8';
15
- import isAdmin from 'is-admin';
16
- import { clearTerminalStringColor, formatBytes } from '../client/components/core/CommonJs.js';
17
-
18
- colors.enable();
19
- dotenv.config();
20
-
21
- // Define your severity levels.
22
- // With them, You can create log files,
23
- // see or hide levels based on the running ENV.
24
- const levels = {
25
- error: 0,
26
- warn: 1,
27
- info: 2,
28
- http: 3,
29
- debug: 4,
30
- };
31
-
32
- // This method set the current severity based on
33
- // the current NODE_ENV: show all the log levels
34
- // if the server was run in development mode; otherwise,
35
- // if it was run in production, show only warn and error messages.
36
- const level = () => 'info'; // (process.env.NODE_ENV || 'development' ? 'debug' : 'warn');
37
-
38
- // Define different colors for each level.
39
- // Colors make the log message more visible,
40
- // adding the ability to focus or ignore messages.
41
-
42
- // Tell winston that you want to link the colors
43
- // defined above to the severity levels.
44
- winston.addColors({
45
- error: 'red',
46
- warn: 'yellow',
47
- info: 'green',
48
- http: 'magenta',
49
- debug: 'white',
50
- });
51
-
52
- // Chose the aspect of your log customizing the log format.
53
- const format = (meta) =>
54
- winston.format.combine(
55
- // winston.format.errors({ stack: true }),
56
- // Add the message timestamp with the preferred format
57
- winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss:ms' }),
58
- // Tell Winston that the logs must be colored
59
- winston.format.colorize({ all: true }),
60
- // Define the format of the message showing the timestamp, the level and the message
61
- winston.format.printf((info) => {
62
- const symbols = Object.getOwnPropertySymbols(info);
63
- return `${`[${meta}]`.green} ${info.timestamp} ${info.level} ${
64
- symbols[1]
65
- ? `${clearTerminalStringColor(info.message)}: ${colorize(JSON.stringify(info[symbols[1]][0], null, 4), {
66
- colors: {
67
- STRING_KEY: 'green',
68
- STRING_LITERAL: 'magenta.bold',
69
- NUMBER_LITERAL: '#FF0000',
70
- },
71
- })}`
72
- : info.message
73
- }`;
74
- }),
75
- );
76
-
77
- /**
78
- * Logs information about the current process environment to the console.
79
- *
80
- * This function is used to log details about
81
- * the execution context, such as command-line arguments,
82
- * environment variables, the process's administrative privileges,
83
- * and the maximum available heap space size.
84
- *
85
- * @param {winston.Logger} logger - A pre-configured Winston logger object.
86
- * @memberof Logger
87
- */
88
- const setUpInfo = async (logger = new winston.Logger()) => {
89
- logger.info('argv', process.argv);
90
- logger.info('env', process.env.NODE_ENV);
91
- logger.info('admin', await isAdmin());
92
- logger.info('--max-old-space-size', {
93
- total_available_size: formatBytes(v8.getHeapStatistics().total_available_size),
94
- });
95
- };
96
-
97
- /**
98
- * The function `loggerFactory` creates a logger instance with specified transports for printing out
99
- * messages.
100
- * @param meta - The `meta` parameter in the `loggerFactory` function is used to extract the last part
101
- * of a URL and use it to create log files in a specific directory.
102
- * @returns {winston.Logger} The `loggerFactory` function returns a logger instance created using Winston logger
103
- * library. The logger instance is configured with various transports for printing out messages to
104
- * different destinations such as the terminal, error.log file, and all.log file. The logger instance
105
- * also has a method `setUpInfo` attached to it for setting up additional information.
106
- * @memberof Logger
107
- */
108
- const loggerFactory = (meta = { url: '' }) => {
109
- meta = meta.url.split('/').pop();
110
- // Define which transports the logger must use to print out messages.
111
- // In this example, we are using three different transports
112
- const transports = [
113
- // Allow the use the terminal to print the messages
114
- new winston.transports.Console(),
115
- // Allow to print all the error level messages inside the error.log file
116
- new winston.transports.File({
117
- filename: `logs/${meta}/error.log`,
118
- level: 'error',
119
- }),
120
- // Allow to print all the error message inside the all.log file
121
- // (also the error log that are also printed inside the error.log(
122
- new winston.transports.File({ filename: `logs/${meta}/all.log` }),
123
- ];
124
-
125
- // Create the logger instance that has to be exported
126
- // and used to log messages.
127
- const logger = winston.createLogger({
128
- defaultMeta: meta,
129
- level: level(),
130
- levels,
131
- format: format(meta),
132
- transports,
133
- // exceptionHandlers: [new winston.transports.File({ filename: 'exceptions.log' })],
134
- // rejectionHandlers: [new winston.transports.File({ filename: 'rejections.log' })],
135
- // exitOnError: false,
136
- });
137
- logger.setUpInfo = async () => {
138
- await setUpInfo(logger);
139
- };
140
- return logger;
141
- };
142
-
143
- /**
144
- * The `loggerMiddleware` function creates a middleware for logging HTTP requests using Morgan with
145
- * custom message format and options.
146
- * @param meta - The `meta` parameter in the `loggerMiddleware` function is an object that contains
147
- * information about the request URL. It has a default value of an empty object `{ url: '' }`. This
148
- * object is used to provide additional metadata for logging purposes.
149
- * @returns {Handler<any, any>} The `loggerMiddleware` function returns a middleware function that uses the Morgan library
150
- * to log HTTP request information. The middleware function formats the log message using predefined
151
- * tokens provided by Morgan and custom tokens like `:host` to include specific request details. The
152
- * log message format includes information such as remote address, HTTP method, host, URL, status code,
153
- * content length, and response time in milliseconds. The middleware
154
- * @memberof Logger
155
- */
156
- const loggerMiddleware = (meta = { url: '' }) => {
157
- const stream = {
158
- // Use the http severity
159
- write: (message) => loggerFactory(meta).http(message),
160
- };
161
-
162
- const skip = (req, res) => process.env.NODE_ENV === 'production';
163
-
164
- morgan.token('host', function (req, res) {
165
- return req.headers['host'];
166
- });
167
-
168
- return morgan(
169
- // Define message format string (this is the default one).
170
- // The message format is made from tokens, and each token is
171
- // defined inside the Morgan library.
172
- // You can create your custom token to show what do you want from a request.
173
- `:remote-addr :method :host:url :status :res[content-length] - :response-time ms`,
174
- // Options: in this case, I overwrote the stream and the skip logic.
175
- // See the methods above.
176
- { stream, skip },
177
- );
178
- };
179
-
180
- export { loggerFactory, loggerMiddleware, setUpInfo };
1
+ /**
2
+ * Module for managing logger control and configuration
3
+ * @module src/server/logger.js
4
+ * @namespace Logger
5
+ */
6
+
7
+ 'use strict';
8
+
9
+ import dotenv from 'dotenv';
10
+ import winston from 'winston';
11
+ import morgan from 'morgan';
12
+ import colorize from 'json-colorizer';
13
+ import colors from 'colors';
14
+ import v8 from 'v8';
15
+ import isAdmin from 'is-admin';
16
+ import { clearTerminalStringColor, formatBytes } from '../client/components/core/CommonJs.js';
17
+
18
+ colors.enable();
19
+ dotenv.config();
20
+
21
+ // Define your severity levels.
22
+ // With them, You can create log files,
23
+ // see or hide levels based on the running ENV.
24
+ const levels = {
25
+ error: 0,
26
+ warn: 1,
27
+ info: 2,
28
+ http: 3,
29
+ debug: 4,
30
+ };
31
+
32
+ // This method set the current severity based on
33
+ // the current NODE_ENV: show all the log levels
34
+ // if the server was run in development mode; otherwise,
35
+ // if it was run in production, show only warn and error messages.
36
+ const level = () => 'info'; // (process.env.NODE_ENV || 'development' ? 'debug' : 'warn');
37
+
38
+ // Define different colors for each level.
39
+ // Colors make the log message more visible,
40
+ // adding the ability to focus or ignore messages.
41
+
42
+ // Tell winston that you want to link the colors
43
+ // defined above to the severity levels.
44
+ winston.addColors({
45
+ error: 'red',
46
+ warn: 'yellow',
47
+ info: 'green',
48
+ http: 'magenta',
49
+ debug: 'white',
50
+ });
51
+
52
+ // Chose the aspect of your log customizing the log format.
53
+ const format = (meta) =>
54
+ winston.format.combine(
55
+ // winston.format.errors({ stack: true }),
56
+ // Add the message timestamp with the preferred format
57
+ winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss:ms' }),
58
+ // Tell Winston that the logs must be colored
59
+ winston.format.colorize({ all: true }),
60
+ // Define the format of the message showing the timestamp, the level and the message
61
+ winston.format.printf((info) => {
62
+ const symbols = Object.getOwnPropertySymbols(info);
63
+ return `${`[${meta}]`.green} ${info.timestamp} ${info.level} ${
64
+ symbols[1]
65
+ ? `${clearTerminalStringColor(info.message)}: ${colorize(JSON.stringify(info[symbols[1]][0], null, 4), {
66
+ colors: {
67
+ STRING_KEY: 'green',
68
+ STRING_LITERAL: 'magenta.bold',
69
+ NUMBER_LITERAL: '#FF0000',
70
+ },
71
+ })}`
72
+ : info.message
73
+ }`;
74
+ }),
75
+ );
76
+
77
+ /**
78
+ * Logs information about the current process environment to the console.
79
+ *
80
+ * This function is used to log details about
81
+ * the execution context, such as command-line arguments,
82
+ * environment variables, the process's administrative privileges,
83
+ * and the maximum available heap space size.
84
+ *
85
+ * @param {winston.Logger} logger - A pre-configured Winston logger object.
86
+ * @memberof Logger
87
+ */
88
+ const setUpInfo = async (logger = new winston.Logger()) => {
89
+ logger.info('argv', process.argv);
90
+ logger.info('platform', process.platform);
91
+ logger.info('env', process.env.NODE_ENV);
92
+ logger.info('admin', await isAdmin());
93
+ logger.info('--max-old-space-size', {
94
+ total_available_size: formatBytes(v8.getHeapStatistics().total_available_size),
95
+ });
96
+ };
97
+
98
+ /**
99
+ * The function `loggerFactory` creates a logger instance with specified transports for printing out
100
+ * messages.
101
+ * @param meta - The `meta` parameter in the `loggerFactory` function is used to extract the last part
102
+ * of a URL and use it to create log files in a specific directory.
103
+ * @returns {winston.Logger} The `loggerFactory` function returns a logger instance created using Winston logger
104
+ * library. The logger instance is configured with various transports for printing out messages to
105
+ * different destinations such as the terminal, error.log file, and all.log file. The logger instance
106
+ * also has a method `setUpInfo` attached to it for setting up additional information.
107
+ * @memberof Logger
108
+ */
109
+ const loggerFactory = (meta = { url: '' }) => {
110
+ meta = meta.url.split('/').pop();
111
+ // Define which transports the logger must use to print out messages.
112
+ // In this example, we are using three different transports
113
+ const transports = [
114
+ // Allow the use the terminal to print the messages
115
+ new winston.transports.Console(),
116
+ // Allow to print all the error level messages inside the error.log file
117
+ new winston.transports.File({
118
+ filename: `logs/${meta}/error.log`,
119
+ level: 'error',
120
+ }),
121
+ // Allow to print all the error message inside the all.log file
122
+ // (also the error log that are also printed inside the error.log(
123
+ new winston.transports.File({ filename: `logs/${meta}/all.log` }),
124
+ ];
125
+
126
+ // Create the logger instance that has to be exported
127
+ // and used to log messages.
128
+ const logger = winston.createLogger({
129
+ defaultMeta: meta,
130
+ level: level(),
131
+ levels,
132
+ format: format(meta),
133
+ transports,
134
+ // exceptionHandlers: [new winston.transports.File({ filename: 'exceptions.log' })],
135
+ // rejectionHandlers: [new winston.transports.File({ filename: 'rejections.log' })],
136
+ // exitOnError: false,
137
+ });
138
+ logger.setUpInfo = async () => {
139
+ await setUpInfo(logger);
140
+ };
141
+ return logger;
142
+ };
143
+
144
+ /**
145
+ * The `loggerMiddleware` function creates a middleware for logging HTTP requests using Morgan with
146
+ * custom message format and options.
147
+ * @param meta - The `meta` parameter in the `loggerMiddleware` function is an object that contains
148
+ * information about the request URL. It has a default value of an empty object `{ url: '' }`. This
149
+ * object is used to provide additional metadata for logging purposes.
150
+ * @returns {Handler<any, any>} The `loggerMiddleware` function returns a middleware function that uses the Morgan library
151
+ * to log HTTP request information. The middleware function formats the log message using predefined
152
+ * tokens provided by Morgan and custom tokens like `:host` to include specific request details. The
153
+ * log message format includes information such as remote address, HTTP method, host, URL, status code,
154
+ * content length, and response time in milliseconds. The middleware
155
+ * @memberof Logger
156
+ */
157
+ const loggerMiddleware = (meta = { url: '' }) => {
158
+ const stream = {
159
+ // Use the http severity
160
+ write: (message) => loggerFactory(meta).http(message),
161
+ };
162
+
163
+ const skip = (req, res) => process.env.NODE_ENV === 'production';
164
+
165
+ morgan.token('host', function (req, res) {
166
+ return req.headers['host'];
167
+ });
168
+
169
+ return morgan(
170
+ // Define message format string (this is the default one).
171
+ // The message format is made from tokens, and each token is
172
+ // defined inside the Morgan library.
173
+ // You can create your custom token to show what do you want from a request.
174
+ `:remote-addr :method :host:url :status :res[content-length] - :response-time ms`,
175
+ // Options: in this case, I overwrote the stream and the skip logic.
176
+ // See the methods above.
177
+ { stream, skip },
178
+ );
179
+ };
180
+
181
+ const underpostASCI = () => `
182
+ ▗▖ ▗▖▗▖ ▗▖▗▄▄▄ ▗▄▄▄▖▗▄▄▖ ▄▄▄▄ ▄▄▄ ▄▄▄ ■
183
+ ▐▌ ▐▌▐▛▚▖▐▌▐▌ █ ▐▌ ▐▌ ▐▌█ █ █ █ ▀▄▄▗▄▟▙▄▖
184
+ ▐▌ ▐▌▐▌ ▝▜▌▐▌ █ ▐▛▀▀▘▐▛▀▚▖█▄▄▄▀ ▀▄▄▄▀ ▄▄▄▀ ▐▌
185
+ ▝▚▄▞▘▐▌ ▐▌▐▙▄▄▀ ▐▙▄▄▖▐▌ ▐▌█ ▐▌
186
+ ▀ ▐▌
187
+
188
+ `;
189
+
190
+ export { loggerFactory, loggerMiddleware, setUpInfo, underpostASCI };
@@ -1,122 +1,122 @@
1
- import detect from 'detect-port';
2
- import fs from 'fs-extra';
3
-
4
- import { publicIp, publicIpv4, publicIpv6 } from 'public-ip';
5
- import { killPortProcess } from 'kill-port-process';
6
- import { loggerFactory } from './logger.js';
7
- import { orderArrayFromAttrInt } from '../client/components/core/CommonJs.js';
8
-
9
- // Network Address Translation Management
10
-
11
- // import dotenv from 'dotenv';
12
- // dotenv.config();
13
-
14
- const logger = loggerFactory(import.meta);
15
-
16
- const network = {
17
- port: {
18
- status: async (ports) => {
19
- const status = [];
20
- for (const port of ports) {
21
- status.push({
22
- port,
23
- open: await new Promise((resolve) =>
24
- detect(port)
25
- .then((_port) => {
26
- if (port == _port)
27
- // `port: ${port} was not occupied`
28
- return resolve(false);
29
-
30
- // `port: ${port} was occupied, try port: ${_port}`
31
- return resolve(true);
32
- })
33
- .catch((error) => resolve(`${error.message}`)),
34
- ),
35
- });
36
- }
37
- return status;
38
- },
39
- kill: async (ports) => await killPortProcess(ports),
40
- portClean: async function (port) {
41
- const [portStatus] = await this.status([port]);
42
- // logger.info('port status', portStatus);
43
- if (portStatus.open) await this.kill([port]);
44
- },
45
- },
46
- };
47
-
48
- const ip = {
49
- public: {
50
- get: async () => await publicIp(), // => 'fe80::200:f8ff:fe21:67cf'
51
- ipv4: async () => await publicIpv4(), // => '46.5.21.123'
52
- ipv6: async () => await publicIpv6(), // => 'fe80::200:f8ff:fe21:67cf'
53
- },
54
- };
55
-
56
- let ipInstance = '';
57
- const networkRouter = {};
58
-
59
- const logRuntimeRouter = () => {
60
- const displayLog = {};
61
-
62
- for (const host of Object.keys(networkRouter))
63
- for (const path of Object.keys(networkRouter[host]))
64
- displayLog[networkRouter[host][path].publicHost] = networkRouter[host][path].local;
65
-
66
- logger.info('Runtime network', displayLog);
67
- };
68
-
69
- const saveRuntimeRouter = () =>
70
- fs.writeFileSync(
71
- `./tmp/runtime-router.${process.argv[3] ? process.argv[3] : 'default'}.json`,
72
- JSON.stringify(networkRouter, null, 4),
73
- 'utf-8',
74
- );
75
-
76
- const listenServerFactory = (logic = async () => {}) => {
77
- return {
78
- listen: async (...args) => (logic ? await logic(...args) : undefined, args[1]()),
79
- };
80
- };
81
-
82
- const listenPortController = async (server, port, metadata) =>
83
- new Promise((resolve) => {
84
- try {
85
- if (!server) server = listenServerFactory();
86
-
87
- const { host, path, client, runtime, meta } = metadata;
88
- const error = [];
89
- if (port === undefined) error.push(`port`);
90
- if (host === undefined) error.push(`host`);
91
- if (path === undefined) error.push(`path`);
92
- if (client === undefined) error.push(`client`);
93
- if (runtime === undefined) error.push(`runtime`);
94
- if (meta === undefined) error.push(`meta`);
95
- if (error.length > 0) throw new Error('Listen port controller requires values: ' + error.join(', '));
96
-
97
- server.listen(port, () => {
98
- if (!networkRouter[host]) networkRouter[host] = {};
99
- networkRouter[host][path] = {
100
- meta,
101
- client,
102
- runtime,
103
- port,
104
- public: `http://${ipInstance}:${port}${path}`,
105
- publicHost:
106
- port === 80
107
- ? `http://${host}${path}`
108
- : port === 443
109
- ? `https://${host}${path}`
110
- : `http://${host}:${port}${path}`,
111
- local: `http://localhost:${port}${path}`,
112
- };
113
-
114
- return resolve(true);
115
- });
116
- } catch (error) {
117
- logger.error(error, { metadata, port, stack: error.stack });
118
- resolve(false);
119
- }
120
- });
121
-
122
- export { ip, network, listenPortController, networkRouter, saveRuntimeRouter, logRuntimeRouter, listenServerFactory };
1
+ import detect from 'detect-port';
2
+ import fs from 'fs-extra';
3
+
4
+ import { publicIp, publicIpv4, publicIpv6 } from 'public-ip';
5
+ import { killPortProcess } from 'kill-port-process';
6
+ import { loggerFactory } from './logger.js';
7
+ import { orderArrayFromAttrInt } from '../client/components/core/CommonJs.js';
8
+
9
+ // Network Address Translation Management
10
+
11
+ // import dotenv from 'dotenv';
12
+ // dotenv.config();
13
+
14
+ const logger = loggerFactory(import.meta);
15
+
16
+ const network = {
17
+ port: {
18
+ status: async (ports) => {
19
+ const status = [];
20
+ for (const port of ports) {
21
+ status.push({
22
+ port,
23
+ open: await new Promise((resolve) =>
24
+ detect(port)
25
+ .then((_port) => {
26
+ if (port == _port)
27
+ // `port: ${port} was not occupied`
28
+ return resolve(false);
29
+
30
+ // `port: ${port} was occupied, try port: ${_port}`
31
+ return resolve(true);
32
+ })
33
+ .catch((error) => resolve(`${error.message}`)),
34
+ ),
35
+ });
36
+ }
37
+ return status;
38
+ },
39
+ kill: async (ports) => await killPortProcess(ports),
40
+ portClean: async function (port) {
41
+ const [portStatus] = await this.status([port]);
42
+ // logger.info('port status', portStatus);
43
+ if (portStatus.open) await this.kill([port]);
44
+ },
45
+ },
46
+ };
47
+
48
+ const ip = {
49
+ public: {
50
+ get: async () => await publicIp(), // => 'fe80::200:f8ff:fe21:67cf'
51
+ ipv4: async () => await publicIpv4(), // => '46.5.21.123'
52
+ ipv6: async () => await publicIpv6(), // => 'fe80::200:f8ff:fe21:67cf'
53
+ },
54
+ };
55
+
56
+ let ipInstance = '';
57
+ const networkRouter = {};
58
+
59
+ const logRuntimeRouter = () => {
60
+ const displayLog = {};
61
+
62
+ for (const host of Object.keys(networkRouter))
63
+ for (const path of Object.keys(networkRouter[host]))
64
+ displayLog[networkRouter[host][path].publicHost] = networkRouter[host][path].local;
65
+
66
+ logger.info('Runtime network', displayLog);
67
+ };
68
+
69
+ const saveRuntimeRouter = () =>
70
+ fs.writeFileSync(
71
+ `./tmp/runtime-router.${process.argv[3] ? process.argv[3] : 'default'}.json`,
72
+ JSON.stringify(networkRouter, null, 4),
73
+ 'utf-8',
74
+ );
75
+
76
+ const listenServerFactory = (logic = async () => {}) => {
77
+ return {
78
+ listen: async (...args) => (logic ? await logic(...args) : undefined, args[1]()),
79
+ };
80
+ };
81
+
82
+ const listenPortController = async (server, port, metadata) =>
83
+ new Promise((resolve) => {
84
+ try {
85
+ if (!server) server = listenServerFactory();
86
+
87
+ const { host, path, client, runtime, meta } = metadata;
88
+ const error = [];
89
+ if (port === undefined) error.push(`port`);
90
+ if (host === undefined) error.push(`host`);
91
+ if (path === undefined) error.push(`path`);
92
+ if (client === undefined) error.push(`client`);
93
+ if (runtime === undefined) error.push(`runtime`);
94
+ if (meta === undefined) error.push(`meta`);
95
+ if (error.length > 0) throw new Error('Listen port controller requires values: ' + error.join(', '));
96
+
97
+ server.listen(port, () => {
98
+ if (!networkRouter[host]) networkRouter[host] = {};
99
+ networkRouter[host][path] = {
100
+ meta,
101
+ client,
102
+ runtime,
103
+ port,
104
+ public: `http://${ipInstance}:${port}${path}`,
105
+ publicHost:
106
+ port === 80
107
+ ? `http://${host}${path}`
108
+ : port === 443
109
+ ? `https://${host}${path}`
110
+ : `http://${host}:${port}${path}`,
111
+ local: `http://localhost:${port}${path}`,
112
+ };
113
+
114
+ return resolve(true);
115
+ });
116
+ } catch (error) {
117
+ logger.error(error, { metadata, port, stack: error.stack });
118
+ resolve(false);
119
+ }
120
+ });
121
+
122
+ export { ip, network, listenPortController, networkRouter, saveRuntimeRouter, logRuntimeRouter, listenServerFactory };