underpost 2.8.637 → 2.8.641
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.
- package/bin/build.js +1 -1
- package/bin/deploy.js +2 -1
- package/bin/index.js +2 -0
- package/docker-compose.yml +1 -1
- package/package.json +1 -3
- package/src/api/default/default.service.js +1 -1
- package/src/api/user/user.service.js +1 -1
- package/src/cli/cron.js +39 -8
- package/src/cli/deploy.js +63 -10
- package/src/cli/image.js +2 -4
- package/src/client/components/core/Account.js +22 -18
- package/src/client/components/core/CalendarCore.js +13 -85
- package/src/client/components/core/CommonJs.js +2 -1
- package/src/client/components/core/EventsUI.js +2 -2
- package/src/client/components/core/FileExplorer.js +86 -78
- package/src/client/components/core/Modal.js +12 -7
- package/src/client/components/core/Panel.js +14 -56
- package/src/client/components/core/PanelForm.js +13 -24
- package/src/client/components/core/Router.js +3 -1
- package/src/client/components/default/RoutesDefault.js +3 -2
- package/src/client/services/default/default.management.js +45 -38
- package/src/index.js +10 -3
- package/src/server/dns.js +9 -1
- package/src/server/json-schema.js +77 -0
- package/src/server/network.js +7 -122
- package/src/server/runtime.js +1 -3
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
function isPlainObject(obj) {
|
|
2
|
+
return obj ? typeof obj === 'object' && Object.getPrototypeOf(obj) === Object.prototype : false;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
const supportType = ['string', 'number', 'array', 'object', 'boolean', 'integer'];
|
|
6
|
+
|
|
7
|
+
function getType(type) {
|
|
8
|
+
if (!type) type = 'string';
|
|
9
|
+
if (supportType.indexOf(type) !== -1) {
|
|
10
|
+
return type;
|
|
11
|
+
}
|
|
12
|
+
return typeof type;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function isSchema(object) {
|
|
16
|
+
if (supportType.indexOf(object.type) !== -1) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function handleSchema(json, schema) {
|
|
23
|
+
Object.assign(schema, json);
|
|
24
|
+
if (schema.type === 'object') {
|
|
25
|
+
delete schema.properties;
|
|
26
|
+
parse(json.properties, schema);
|
|
27
|
+
}
|
|
28
|
+
if (schema.type === 'array') {
|
|
29
|
+
delete schema.items;
|
|
30
|
+
schema.items = {};
|
|
31
|
+
parse(json.items, schema.items);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function handleArray(arr, schema) {
|
|
36
|
+
schema.type = 'array';
|
|
37
|
+
let props = (schema.items = {});
|
|
38
|
+
parse(arr[0], props);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function handleObject(json, schema) {
|
|
42
|
+
if (isSchema(json)) {
|
|
43
|
+
return handleSchema(json, schema);
|
|
44
|
+
}
|
|
45
|
+
schema.type = 'object';
|
|
46
|
+
schema.required = [];
|
|
47
|
+
let props = (schema.properties = {});
|
|
48
|
+
for (let key in json) {
|
|
49
|
+
let item = json[key];
|
|
50
|
+
let curSchema = (props[key] = {});
|
|
51
|
+
if (key[0] === '*') {
|
|
52
|
+
delete props[key];
|
|
53
|
+
key = key.substr(1);
|
|
54
|
+
schema.required.push(key);
|
|
55
|
+
curSchema = props[key] = {};
|
|
56
|
+
}
|
|
57
|
+
parse(item, curSchema);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function parse(json, schema) {
|
|
62
|
+
if (Array.isArray(json)) {
|
|
63
|
+
handleArray(json, schema);
|
|
64
|
+
} else if (isPlainObject(json)) {
|
|
65
|
+
handleObject(json, schema);
|
|
66
|
+
} else {
|
|
67
|
+
schema.type = getType(json);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function ejs(data) {
|
|
72
|
+
let JsonSchema = {};
|
|
73
|
+
parse(data, JsonSchema);
|
|
74
|
+
return JsonSchema;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export { ejs };
|
package/src/server/network.js
CHANGED
|
@@ -1,123 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import { publicIp, publicIpv4, publicIpv6 } from 'public-ip';
|
|
1
|
+
import Underpost from '../index.js';
|
|
4
2
|
import { actionInitLog, loggerFactory } from './logger.js';
|
|
5
|
-
import { DataBaseProvider } from '../db/DataBaseProvider.js';
|
|
6
|
-
import { getDeployId } from './conf.js';
|
|
7
|
-
|
|
8
|
-
// Network Address Translation Management
|
|
9
|
-
|
|
10
|
-
// import dotenv from 'dotenv';
|
|
11
|
-
// dotenv.config();
|
|
12
3
|
|
|
13
4
|
const logger = loggerFactory(import.meta);
|
|
14
5
|
|
|
15
|
-
const ip = {
|
|
16
|
-
public: {
|
|
17
|
-
get: async () => await publicIp(), // => 'fe80::200:f8ff:fe21:67cf'
|
|
18
|
-
ipv4: async () => await publicIpv4(), // => '46.5.21.123'
|
|
19
|
-
ipv6: async () => await publicIpv6(), // => 'fe80::200:f8ff:fe21:67cf'
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
let ipInstance = '';
|
|
24
|
-
const networkRouter = {};
|
|
25
|
-
|
|
26
6
|
const logRuntimeRouter = () => {
|
|
27
7
|
const displayLog = {};
|
|
28
8
|
|
|
29
|
-
for (const host of Object.keys(
|
|
30
|
-
for (const path of Object.keys(
|
|
31
|
-
displayLog[
|
|
9
|
+
for (const host of Object.keys(Underpost.deployNetwork))
|
|
10
|
+
for (const path of Object.keys(Underpost.deployNetwork[host]))
|
|
11
|
+
displayLog[Underpost.deployNetwork[host][path].publicHost] = Underpost.deployNetwork[host][path].local;
|
|
32
12
|
|
|
33
13
|
logger.info('Runtime network', displayLog);
|
|
34
14
|
};
|
|
35
15
|
|
|
36
|
-
const saveRuntimeRouter = async () => {
|
|
37
|
-
try {
|
|
38
|
-
const deployId = process.env.DEFAULT_DEPLOY_ID;
|
|
39
|
-
const host = process.env.DEFAULT_DEPLOY_HOST;
|
|
40
|
-
const path = process.env.DEFAULT_DEPLOY_PATH;
|
|
41
|
-
const confServerPath = `./engine-private/conf/${deployId}/conf.server.json`;
|
|
42
|
-
if (!deployId || !host || !path || !fs.existsSync(confServerPath)) {
|
|
43
|
-
// logger.warn('default deploy instance not found');
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
const confServer = JSON.parse(fs.readFileSync(confServerPath, 'utf8'));
|
|
47
|
-
const { db } = confServer[host][path];
|
|
48
|
-
|
|
49
|
-
let closeConn;
|
|
50
|
-
if (!DataBaseProvider.instance[`${host}${path}`]) {
|
|
51
|
-
await DataBaseProvider.load({ apis: ['instance'], host, path, db });
|
|
52
|
-
closeConn = true;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/** @type {import('../api/instance/instance.model.js').InstanceModel} */
|
|
56
|
-
const Instance = DataBaseProvider.instance[`${host}${path}`].mongoose.models.Instance;
|
|
57
|
-
|
|
58
|
-
for (const _host of Object.keys(networkRouter)) {
|
|
59
|
-
for (const _path of Object.keys(networkRouter[_host])) {
|
|
60
|
-
const body = {
|
|
61
|
-
host: _host,
|
|
62
|
-
path: _path,
|
|
63
|
-
deployId: getDeployId(),
|
|
64
|
-
client: networkRouter[_host][_path].client,
|
|
65
|
-
runtime: networkRouter[_host][_path].runtime,
|
|
66
|
-
port: networkRouter[_host][_path].port,
|
|
67
|
-
apis: networkRouter[_host][_path].apis,
|
|
68
|
-
};
|
|
69
|
-
const instance = await Instance.findOne({ deployId: body.deployId, host: _host, path: _path });
|
|
70
|
-
if (instance) {
|
|
71
|
-
await Instance.findByIdAndUpdate(instance._id, body);
|
|
72
|
-
} else {
|
|
73
|
-
await new Instance(body).save();
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (closeConn) await DataBaseProvider.instance[`${host}${path}`].mongoose.close();
|
|
79
|
-
} catch (error) {
|
|
80
|
-
logger.error(error, error.stack);
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const netWorkCron = [];
|
|
85
|
-
|
|
86
|
-
const saveRuntimeCron = async () => {
|
|
87
|
-
try {
|
|
88
|
-
const deployId = process.env.DEFAULT_DEPLOY_ID;
|
|
89
|
-
const host = process.env.DEFAULT_DEPLOY_HOST;
|
|
90
|
-
const path = process.env.DEFAULT_DEPLOY_PATH;
|
|
91
|
-
const confServerPath = `./engine-private/conf/${deployId}/conf.server.json`;
|
|
92
|
-
const confServer = JSON.parse(fs.readFileSync(confServerPath, 'utf8'));
|
|
93
|
-
const { db } = confServer[host][path];
|
|
94
|
-
|
|
95
|
-
let closeConn;
|
|
96
|
-
if (!DataBaseProvider.instance[`${host}${path}`]) {
|
|
97
|
-
await DataBaseProvider.load({ apis: ['cron'], host, path, db });
|
|
98
|
-
closeConn = true;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/** @type {import('../api/cron/cron.model.js').CronModel} */
|
|
102
|
-
const Cron = DataBaseProvider.instance[`${host}${path}`].mongoose.models.Cron;
|
|
103
|
-
|
|
104
|
-
// await Cron.insertMany(netWorkCron);
|
|
105
|
-
|
|
106
|
-
for (const cronInstance of netWorkCron) {
|
|
107
|
-
const cron = await Cron.findOne({ deployId: cronInstance.deployId, jobId: cronInstance.jobId });
|
|
108
|
-
if (cron) {
|
|
109
|
-
await Cron.findByIdAndUpdate(cron._id, cronInstance);
|
|
110
|
-
} else {
|
|
111
|
-
await new Cron(cronInstance).save();
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (closeConn) await DataBaseProvider.instance[`${host}${path}`].mongoose.close();
|
|
116
|
-
} catch (error) {
|
|
117
|
-
logger.error(error, error.stack);
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
|
|
121
16
|
const listenServerFactory = (logic = async () => {}) => {
|
|
122
17
|
return {
|
|
123
18
|
listen: async (...args) => (
|
|
@@ -150,13 +45,12 @@ const listenPortController = async (server, port, metadata) =>
|
|
|
150
45
|
if (error.length > 0) throw new Error('Listen port controller requires values: ' + error.join(', '));
|
|
151
46
|
|
|
152
47
|
server.listen(port, () => {
|
|
153
|
-
if (!
|
|
154
|
-
|
|
48
|
+
if (!Underpost.deployNetwork[host]) Underpost.deployNetwork[host] = {};
|
|
49
|
+
Underpost.deployNetwork[host][path] = {
|
|
155
50
|
meta,
|
|
156
51
|
client,
|
|
157
52
|
runtime,
|
|
158
53
|
port,
|
|
159
|
-
public: `http://${ipInstance}:${port}${path}`,
|
|
160
54
|
publicHost:
|
|
161
55
|
port === 80
|
|
162
56
|
? `http://${host}${path}`
|
|
@@ -175,13 +69,4 @@ const listenPortController = async (server, port, metadata) =>
|
|
|
175
69
|
}
|
|
176
70
|
});
|
|
177
71
|
|
|
178
|
-
export {
|
|
179
|
-
ip,
|
|
180
|
-
listenPortController,
|
|
181
|
-
networkRouter,
|
|
182
|
-
netWorkCron,
|
|
183
|
-
saveRuntimeRouter,
|
|
184
|
-
logRuntimeRouter,
|
|
185
|
-
listenServerFactory,
|
|
186
|
-
saveRuntimeCron,
|
|
187
|
-
};
|
|
72
|
+
export { listenPortController, logRuntimeRouter, listenServerFactory };
|
package/src/server/runtime.js
CHANGED
|
@@ -9,7 +9,7 @@ import compression from 'compression';
|
|
|
9
9
|
|
|
10
10
|
import { createServer } from 'http';
|
|
11
11
|
import { getRootDirectory } from './process.js';
|
|
12
|
-
import { listenPortController,
|
|
12
|
+
import { listenPortController, logRuntimeRouter, listenServerFactory } from './network.js';
|
|
13
13
|
import { loggerFactory, loggerMiddleware } from './logger.js';
|
|
14
14
|
import { getCapVariableName, newInstance } from '../client/components/core/CommonJs.js';
|
|
15
15
|
import { Xampp } from '../runtime/xampp/Xampp.js';
|
|
@@ -41,7 +41,6 @@ const buildRuntime = async () => {
|
|
|
41
41
|
// logger.info('promCounterOption', promCounterOption);
|
|
42
42
|
|
|
43
43
|
const requestCounter = new promClient.Counter(promCounterOption);
|
|
44
|
-
const ipInstance = ''; // await ip.public.ipv4();
|
|
45
44
|
const initPort = parseInt(process.env.PORT) + 1;
|
|
46
45
|
let currentPort = initPort;
|
|
47
46
|
const confServer = JSON.parse(fs.readFileSync(`./conf/conf.server.json`, 'utf8'));
|
|
@@ -484,7 +483,6 @@ const buildRuntime = async () => {
|
|
|
484
483
|
if (Xampp.enabled() && Xampp.router) Xampp.initService();
|
|
485
484
|
if (Lampp.enabled() && Lampp.router) Lampp.initService();
|
|
486
485
|
|
|
487
|
-
saveRuntimeRouter();
|
|
488
486
|
logRuntimeRouter();
|
|
489
487
|
};
|
|
490
488
|
|