lupine.api 1.1.57 → 1.1.59
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/README.md +3 -3
- package/admin/admin-about.tsx +12 -16
- package/admin/admin-config.tsx +47 -44
- package/admin/admin-css.tsx +3 -3
- package/admin/admin-db.tsx +75 -75
- package/admin/admin-frame-helper.tsx +364 -364
- package/admin/admin-frame.tsx +164 -164
- package/admin/admin-index.tsx +65 -65
- package/admin/admin-login.tsx +111 -111
- package/admin/admin-menu-edit.tsx +637 -637
- package/admin/admin-menu-list.tsx +87 -87
- package/admin/admin-page-edit.tsx +564 -564
- package/admin/admin-page-list.tsx +83 -83
- package/admin/admin-performance.tsx +28 -28
- package/admin/admin-release.tsx +427 -404
- package/admin/admin-resources.tsx +382 -382
- package/admin/admin-shell.tsx +89 -89
- package/admin/admin-table-data.tsx +146 -146
- package/admin/admin-table-list.tsx +230 -230
- package/admin/admin-test-animations.tsx +395 -395
- package/admin/admin-test-component.tsx +823 -808
- package/admin/admin-test-edit.tsx +319 -319
- package/admin/admin-test-themes.tsx +56 -56
- package/admin/admin-tokens.tsx +338 -338
- package/admin/design/admin-design.tsx +174 -174
- package/admin/design/block-grid.tsx +36 -36
- package/admin/design/block-grid1.tsx +21 -21
- package/admin/design/block-paragraph.tsx +19 -19
- package/admin/design/block-title.tsx +19 -19
- package/admin/design/design-block-box.tsx +140 -140
- package/admin/design/drag-data.tsx +24 -24
- package/admin/index.ts +9 -9
- package/admin/package.json +15 -15
- package/admin/tsconfig.json +127 -127
- package/dev/copy-folder.js +32 -32
- package/dev/cp-index-html.js +69 -69
- package/dev/file-utils.js +12 -12
- package/dev/index.js +18 -19
- package/dev/package.json +12 -12
- package/dev/plugin-ifelse.js +168 -168
- package/dev/plugin-ifelse.test.js +37 -37
- package/dev/run-cmd.js +14 -14
- package/dev/send-request.js +12 -12
- package/package.json +55 -55
- package/src/admin-api/admin-api-helper.ts +210 -205
- package/src/admin-api/admin-api.ts +65 -65
- package/src/admin-api/admin-auth.ts +152 -146
- package/src/admin-api/admin-config.ts +94 -84
- package/src/admin-api/admin-csv.ts +94 -94
- package/src/admin-api/admin-db.ts +269 -269
- package/src/admin-api/admin-menu.ts +135 -135
- package/src/admin-api/admin-page.ts +135 -135
- package/src/admin-api/admin-performance.ts +128 -128
- package/src/admin-api/admin-release.ts +703 -700
- package/src/admin-api/admin-resources.ts +318 -318
- package/src/admin-api/admin-token-helper.ts +82 -79
- package/src/admin-api/admin-tokens.ts +90 -90
- package/src/admin-api/index.ts +2 -2
- package/src/admin-api/web-config-api.ts +19 -19
- package/src/api/api-cache.ts +103 -103
- package/src/api/api-helper.ts +44 -44
- package/src/api/api-module.ts +67 -60
- package/src/api/api-router.ts +177 -177
- package/src/api/api-shared-storage.ts +64 -64
- package/src/api/async-storage.ts +5 -5
- package/src/api/debug-service.ts +56 -56
- package/src/api/encode-html.ts +27 -27
- package/src/api/handle-status.ts +75 -75
- package/src/api/index.ts +15 -16
- package/src/api/mini-web-socket.ts +270 -270
- package/src/api/server-content-type.ts +82 -82
- package/src/api/server-render.ts +235 -215
- package/src/api/shell-service.ts +74 -74
- package/src/api/simple-storage.ts +80 -80
- package/src/api/static-server.ts +128 -125
- package/src/api/to-client-delivery.ts +26 -26
- package/src/app/app-cache.ts +55 -55
- package/src/app/app-helper.ts +62 -62
- package/src/app/app-message.ts +109 -109
- package/src/app/app-shared-storage.ts +363 -363
- package/src/app/app-start.ts +136 -136
- package/src/app/cleanup-exit.ts +16 -16
- package/src/app/host-to-path.ts +38 -38
- package/src/app/index.ts +11 -11
- package/src/app/process-dev-requests.ts +130 -130
- package/src/app/web-listener.ts +294 -294
- package/src/app/web-processor.ts +47 -42
- package/src/app/web-server.ts +100 -100
- package/src/common-js/web-env.js +104 -104
- package/src/index.ts +7 -7
- package/src/lang/api-lang-en.ts +26 -26
- package/src/lang/api-lang-zh-cn.ts +27 -27
- package/src/lang/index.ts +2 -2
- package/src/lang/lang-helper.ts +76 -76
- package/src/lang/lang-props.ts +6 -6
- package/src/lib/db/db-helper.ts +23 -23
- package/src/lib/db/db-mysql.ts +249 -250
- package/src/lib/db/db-sqlite.ts +101 -101
- package/src/lib/db/db.spec.ts +28 -28
- package/src/lib/db/db.ts +325 -325
- package/src/lib/db/index.ts +5 -5
- package/src/lib/index.ts +3 -3
- package/src/lib/logger.spec.ts +214 -214
- package/src/lib/logger.ts +281 -281
- package/src/lib/runtime-require.ts +37 -37
- package/src/lib/utils/cookie-util.ts +34 -34
- package/src/lib/utils/crypto.ts +58 -58
- package/src/lib/utils/date-utils.ts +317 -317
- package/src/lib/utils/deep-merge.ts +37 -37
- package/src/lib/utils/delay.ts +12 -12
- package/src/lib/utils/file-setting.ts +55 -55
- package/src/lib/utils/format-bytes.ts +11 -11
- package/src/lib/utils/fs-utils.ts +158 -158
- package/src/lib/utils/get-env.ts +27 -27
- package/src/lib/utils/index.ts +12 -12
- package/src/lib/utils/is-type.ts +48 -48
- package/src/lib/utils/load-env.ts +14 -14
- package/src/lib/utils/pad.ts +6 -6
- package/src/models/api-base.ts +5 -5
- package/src/models/api-module-props.ts +10 -11
- package/src/models/api-router-props.ts +26 -26
- package/src/models/app-cache-props.ts +33 -33
- package/src/models/app-data-props.ts +10 -10
- package/src/models/app-helper-props.ts +6 -6
- package/src/models/app-shared-storage-props.ts +38 -38
- package/src/models/app-start-props.ts +18 -18
- package/src/models/async-storage-props.ts +13 -13
- package/src/models/db-config.ts +30 -30
- package/src/models/host-to-path-props.ts +12 -12
- package/src/models/index.ts +16 -16
- package/src/models/json-object.ts +8 -8
- package/src/models/locals-props.ts +36 -36
- package/src/models/logger-props.ts +84 -84
- package/src/models/simple-storage-props.ts +13 -14
- package/src/models/to-client-delivery-props.ts +6 -6
- package/tsconfig.json +115 -115
- package/dev/plugin-gen-versions.js +0 -20
package/src/app/app-start.ts
CHANGED
|
@@ -1,136 +1,136 @@
|
|
|
1
|
-
import cluster from 'cluster';
|
|
2
|
-
import { WebProcessor } from './web-processor';
|
|
3
|
-
import { appHelper } from './app-helper';
|
|
4
|
-
import { processMessageFromPrimary, processMessageFromWorker } from './app-message';
|
|
5
|
-
import { WebServer } from './web-server';
|
|
6
|
-
import { processDevRequests } from './process-dev-requests';
|
|
7
|
-
import { appCache } from './app-cache';
|
|
8
|
-
import { AppStartProps, InitStartProps, AppCacheGlobal, AppCacheKeys } from '../models';
|
|
9
|
-
import { appStorage } from './app-shared-storage';
|
|
10
|
-
import { HostToPath } from './host-to-path';
|
|
11
|
-
import { _exitApp, cleanupAndExit } from './cleanup-exit';
|
|
12
|
-
import { receiveMessageFromLoader } from './app-message';
|
|
13
|
-
|
|
14
|
-
// Don't use logger before set process message
|
|
15
|
-
class AppStart {
|
|
16
|
-
debug: boolean = false;
|
|
17
|
-
webServer: WebServer | undefined;
|
|
18
|
-
|
|
19
|
-
getWorkerId() {
|
|
20
|
-
return cluster.worker ? cluster.worker.id : -1;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async start(props: AppStartProps, webServer?: WebServer) {
|
|
24
|
-
// if it's started from spawn, wait for old master to clear ports
|
|
25
|
-
if (cluster.isPrimary && process.env.RESTARTING === '1') {
|
|
26
|
-
console.log(`New app ${process.pid} RESTARTING.`);
|
|
27
|
-
await new Promise((r) => setTimeout(r, 100));
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
this.debug = props.debug;
|
|
31
|
-
this.bindProcess();
|
|
32
|
-
|
|
33
|
-
appCache.set(AppCacheGlobal, AppCacheKeys.APP_DEBUG, props.debug);
|
|
34
|
-
// appCache.set(AppCacheGlobal, AppCacheKeys.APP_ENV_FILE, props.appEnvFile);
|
|
35
|
-
appCache.set(AppCacheGlobal, AppCacheKeys.START_TIME, new Date());
|
|
36
|
-
appCache.set(AppCacheGlobal, AppCacheKeys.RENDER_PAGE_FUNCTIONS, props.renderPageFunctions);
|
|
37
|
-
const appsList = props.apiConfig.webHostMap.map((item) => item.appName);
|
|
38
|
-
appCache.set(AppCacheGlobal, AppCacheKeys.APP_LIST, appsList);
|
|
39
|
-
|
|
40
|
-
this.webServer = webServer || new WebServer();
|
|
41
|
-
|
|
42
|
-
// call the Logger after initLog
|
|
43
|
-
console.log(
|
|
44
|
-
`${process.pid} - ${
|
|
45
|
-
cluster.isPrimary ? 'Primary Process' : 'Worker Process'
|
|
46
|
-
}, Starting Server, path: ${process.cwd()}`
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
// when it's cluster.isPrimary or props.debug, initialize the shared storage first
|
|
50
|
-
if (cluster.isPrimary) {
|
|
51
|
-
for (let appConfig of props.apiConfig.webHostMap) {
|
|
52
|
-
await appStorage.load(appConfig.appName, appConfig.dataPath);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (!cluster.isPrimary) {
|
|
57
|
-
console.log(`${process.pid} - Worker id ${this.getWorkerId()}`);
|
|
58
|
-
|
|
59
|
-
process.on('message', processMessageFromPrimary);
|
|
60
|
-
|
|
61
|
-
HostToPath.setHostToPathList(props.apiConfig.webHostMap);
|
|
62
|
-
appHelper.loadApi(props.apiConfig);
|
|
63
|
-
this.initServer(props.serverConfig);
|
|
64
|
-
} else if (cluster.isPrimary) {
|
|
65
|
-
const numCPUs = props.debug ? 1 : require('os').cpus().length;
|
|
66
|
-
console.log(`${process.pid} - Primary Process is trying to fork ${numCPUs} processes`);
|
|
67
|
-
|
|
68
|
-
receiveMessageFromLoader();
|
|
69
|
-
|
|
70
|
-
for (let i = 0; i < numCPUs; i++) {
|
|
71
|
-
let worker = cluster.fork();
|
|
72
|
-
worker.on('message', processMessageFromWorker);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
cluster.on('death', (worker: any) => {
|
|
76
|
-
if (!_exitApp.isExiting) {
|
|
77
|
-
console.log(`${worker.pid} - Worker died; starting a new one...`);
|
|
78
|
-
cluster.fork();
|
|
79
|
-
} else {
|
|
80
|
-
console.log(`${worker.pid} - Worker exited during restart`);
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
bindProcess() {
|
|
87
|
-
if (cluster.isPrimary) {
|
|
88
|
-
// it looks like the child processes are hung up here
|
|
89
|
-
process.stdin.resume(); // so the program will not close instantly, keep isPrimary process running
|
|
90
|
-
}
|
|
91
|
-
// Emitted whenever a no-error-handler Promise is rejected
|
|
92
|
-
process.on('unhandledRejection', (reason: string, promise) => {
|
|
93
|
-
console.error(`${process.pid} - Process on unhandledRejection, promise: `, promise, ', reason: ', reason);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
// do something when app is closing
|
|
97
|
-
process.on('beforeExit', async () => {
|
|
98
|
-
await cleanupAndExit();
|
|
99
|
-
});
|
|
100
|
-
process.on('exit', (ret) => {
|
|
101
|
-
console.log(`${process.pid} - Process on exit, code: ${ret}`);
|
|
102
|
-
});
|
|
103
|
-
// catches uncaught exceptions
|
|
104
|
-
process.on('uncaughtException', (err: Error) => {
|
|
105
|
-
console.error(`${process.pid} - Process on uncaughtException: `, err);
|
|
106
|
-
console.error(err.stack);
|
|
107
|
-
});
|
|
108
|
-
// catches ctrl+c event and others
|
|
109
|
-
['SIGTERM', 'SIGHUP', 'SIGINT', 'SIGINT', 'SIGBREAK'].forEach((evt) => process.on(evt, cleanupAndExit));
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
async initServer(config: InitStartProps) {
|
|
113
|
-
const bindIp = config.bindIp || '::';
|
|
114
|
-
const httpPort = config.httpPort;
|
|
115
|
-
const httpsPort = config.httpsPort;
|
|
116
|
-
const sslKeyPath = config.sslKeyPath || '';
|
|
117
|
-
const sslCrtPath = config.sslCrtPath || '';
|
|
118
|
-
|
|
119
|
-
console.log(`${process.pid} - Starting Web Server, httpPort: ${httpPort}, httpsPort: ${httpsPort}`);
|
|
120
|
-
// for dev to refresh the FE or stop the server
|
|
121
|
-
if (this.debug) {
|
|
122
|
-
WebProcessor.enableDebug('/debug', processDevRequests);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const httpServer = httpPort && this.webServer!.startHttp(httpPort, bindIp);
|
|
126
|
-
const heepsServer = httpsPort && this.webServer!.startHttps(httpsPort, bindIp, sslKeyPath, sslCrtPath);
|
|
127
|
-
|
|
128
|
-
process.on('SIGTERM', () => {
|
|
129
|
-
console.log(`${process.pid} - Worker closing servers...`);
|
|
130
|
-
httpServer && httpServer.close();
|
|
131
|
-
heepsServer && heepsServer.close();
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export const appStart = /* @__PURE__ */ new AppStart();
|
|
1
|
+
import cluster from 'cluster';
|
|
2
|
+
import { WebProcessor } from './web-processor';
|
|
3
|
+
import { appHelper } from './app-helper';
|
|
4
|
+
import { processMessageFromPrimary, processMessageFromWorker } from './app-message';
|
|
5
|
+
import { WebServer } from './web-server';
|
|
6
|
+
import { processDevRequests } from './process-dev-requests';
|
|
7
|
+
import { appCache } from './app-cache';
|
|
8
|
+
import { AppStartProps, InitStartProps, AppCacheGlobal, AppCacheKeys } from '../models';
|
|
9
|
+
import { appStorage } from './app-shared-storage';
|
|
10
|
+
import { HostToPath } from './host-to-path';
|
|
11
|
+
import { _exitApp, cleanupAndExit } from './cleanup-exit';
|
|
12
|
+
import { receiveMessageFromLoader } from './app-message';
|
|
13
|
+
|
|
14
|
+
// Don't use logger before set process message
|
|
15
|
+
class AppStart {
|
|
16
|
+
debug: boolean = false;
|
|
17
|
+
webServer: WebServer | undefined;
|
|
18
|
+
|
|
19
|
+
getWorkerId() {
|
|
20
|
+
return cluster.worker ? cluster.worker.id : -1;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async start(props: AppStartProps, webServer?: WebServer) {
|
|
24
|
+
// if it's started from spawn, wait for old master to clear ports
|
|
25
|
+
if (cluster.isPrimary && process.env.RESTARTING === '1') {
|
|
26
|
+
console.log(`New app ${process.pid} RESTARTING.`);
|
|
27
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
this.debug = props.debug;
|
|
31
|
+
this.bindProcess();
|
|
32
|
+
|
|
33
|
+
appCache.set(AppCacheGlobal, AppCacheKeys.APP_DEBUG, props.debug);
|
|
34
|
+
// appCache.set(AppCacheGlobal, AppCacheKeys.APP_ENV_FILE, props.appEnvFile);
|
|
35
|
+
appCache.set(AppCacheGlobal, AppCacheKeys.START_TIME, new Date());
|
|
36
|
+
appCache.set(AppCacheGlobal, AppCacheKeys.RENDER_PAGE_FUNCTIONS, props.renderPageFunctions);
|
|
37
|
+
const appsList = props.apiConfig.webHostMap.map((item) => item.appName);
|
|
38
|
+
appCache.set(AppCacheGlobal, AppCacheKeys.APP_LIST, appsList);
|
|
39
|
+
|
|
40
|
+
this.webServer = webServer || new WebServer();
|
|
41
|
+
|
|
42
|
+
// call the Logger after initLog
|
|
43
|
+
console.log(
|
|
44
|
+
`${process.pid} - ${
|
|
45
|
+
cluster.isPrimary ? 'Primary Process' : 'Worker Process'
|
|
46
|
+
}, Starting Server, path: ${process.cwd()}`
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
// when it's cluster.isPrimary or props.debug, initialize the shared storage first
|
|
50
|
+
if (cluster.isPrimary) {
|
|
51
|
+
for (let appConfig of props.apiConfig.webHostMap) {
|
|
52
|
+
await appStorage.load(appConfig.appName, appConfig.dataPath);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (!cluster.isPrimary) {
|
|
57
|
+
console.log(`${process.pid} - Worker id ${this.getWorkerId()}`);
|
|
58
|
+
|
|
59
|
+
process.on('message', processMessageFromPrimary);
|
|
60
|
+
|
|
61
|
+
HostToPath.setHostToPathList(props.apiConfig.webHostMap);
|
|
62
|
+
appHelper.loadApi(props.apiConfig);
|
|
63
|
+
this.initServer(props.serverConfig);
|
|
64
|
+
} else if (cluster.isPrimary) {
|
|
65
|
+
const numCPUs = props.debug ? 1 : require('os').cpus().length;
|
|
66
|
+
console.log(`${process.pid} - Primary Process is trying to fork ${numCPUs} processes`);
|
|
67
|
+
|
|
68
|
+
receiveMessageFromLoader();
|
|
69
|
+
|
|
70
|
+
for (let i = 0; i < numCPUs; i++) {
|
|
71
|
+
let worker = cluster.fork();
|
|
72
|
+
worker.on('message', processMessageFromWorker);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
cluster.on('death', (worker: any) => {
|
|
76
|
+
if (!_exitApp.isExiting) {
|
|
77
|
+
console.log(`${worker.pid} - Worker died; starting a new one...`);
|
|
78
|
+
cluster.fork();
|
|
79
|
+
} else {
|
|
80
|
+
console.log(`${worker.pid} - Worker exited during restart`);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
bindProcess() {
|
|
87
|
+
if (cluster.isPrimary) {
|
|
88
|
+
// it looks like the child processes are hung up here
|
|
89
|
+
process.stdin.resume(); // so the program will not close instantly, keep isPrimary process running
|
|
90
|
+
}
|
|
91
|
+
// Emitted whenever a no-error-handler Promise is rejected
|
|
92
|
+
process.on('unhandledRejection', (reason: string, promise) => {
|
|
93
|
+
console.error(`${process.pid} - Process on unhandledRejection, promise: `, promise, ', reason: ', reason);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// do something when app is closing
|
|
97
|
+
process.on('beforeExit', async () => {
|
|
98
|
+
await cleanupAndExit();
|
|
99
|
+
});
|
|
100
|
+
process.on('exit', (ret) => {
|
|
101
|
+
console.log(`${process.pid} - Process on exit, code: ${ret}`);
|
|
102
|
+
});
|
|
103
|
+
// catches uncaught exceptions
|
|
104
|
+
process.on('uncaughtException', (err: Error) => {
|
|
105
|
+
console.error(`${process.pid} - Process on uncaughtException: `, err);
|
|
106
|
+
console.error(err.stack);
|
|
107
|
+
});
|
|
108
|
+
// catches ctrl+c event and others
|
|
109
|
+
['SIGTERM', 'SIGHUP', 'SIGINT', 'SIGINT', 'SIGBREAK'].forEach((evt) => process.on(evt, cleanupAndExit));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async initServer(config: InitStartProps) {
|
|
113
|
+
const bindIp = config.bindIp || '::';
|
|
114
|
+
const httpPort = config.httpPort;
|
|
115
|
+
const httpsPort = config.httpsPort;
|
|
116
|
+
const sslKeyPath = config.sslKeyPath || '';
|
|
117
|
+
const sslCrtPath = config.sslCrtPath || '';
|
|
118
|
+
|
|
119
|
+
console.log(`${process.pid} - Starting Web Server, httpPort: ${httpPort}, httpsPort: ${httpsPort}`);
|
|
120
|
+
// for dev to refresh the FE or stop the server
|
|
121
|
+
if (this.debug) {
|
|
122
|
+
WebProcessor.enableDebug('/debug', processDevRequests);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const httpServer = httpPort && this.webServer!.startHttp(httpPort, bindIp);
|
|
126
|
+
const heepsServer = httpsPort && this.webServer!.startHttps(httpsPort, bindIp, sslKeyPath, sslCrtPath);
|
|
127
|
+
|
|
128
|
+
process.on('SIGTERM', () => {
|
|
129
|
+
console.log(`${process.pid} - Worker closing servers...`);
|
|
130
|
+
httpServer && httpServer.close();
|
|
131
|
+
heepsServer && heepsServer.close();
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export const appStart = /* @__PURE__ */ new AppStart();
|
package/src/app/cleanup-exit.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import cluster from 'cluster';
|
|
2
|
-
import { appStorage } from './app-shared-storage';
|
|
3
|
-
|
|
4
|
-
export const _exitApp = {
|
|
5
|
-
isExiting: false,
|
|
6
|
-
};
|
|
7
|
-
export const cleanupAndExit = async () => {
|
|
8
|
-
console.log(`${process.pid} - Process on SIGINT, exit.`);
|
|
9
|
-
// save shared storage first
|
|
10
|
-
if (cluster.isPrimary) {
|
|
11
|
-
// save only happens once
|
|
12
|
-
await appStorage.save('', true);
|
|
13
|
-
}
|
|
14
|
-
_exitApp.isExiting = true;
|
|
15
|
-
process.exit(0);
|
|
16
|
-
};
|
|
1
|
+
import cluster from 'cluster';
|
|
2
|
+
import { appStorage } from './app-shared-storage';
|
|
3
|
+
|
|
4
|
+
export const _exitApp = {
|
|
5
|
+
isExiting: false,
|
|
6
|
+
};
|
|
7
|
+
export const cleanupAndExit = async () => {
|
|
8
|
+
console.log(`${process.pid} - Process on SIGINT, exit.`);
|
|
9
|
+
// save shared storage first
|
|
10
|
+
if (cluster.isPrimary) {
|
|
11
|
+
// save only happens once
|
|
12
|
+
await appStorage.save('', true);
|
|
13
|
+
}
|
|
14
|
+
_exitApp.isExiting = true;
|
|
15
|
+
process.exit(0);
|
|
16
|
+
};
|
package/src/app/host-to-path.ts
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
// const request = require('request');
|
|
2
|
-
import { Logger } from '../lib';
|
|
3
|
-
import { HostToPathProps } from '../models';
|
|
4
|
-
|
|
5
|
-
const logger = new Logger('HostToPath');
|
|
6
|
-
export class HostToPath {
|
|
7
|
-
static props: HostToPathProps[] = [];
|
|
8
|
-
|
|
9
|
-
// this should be initialized before any request
|
|
10
|
-
static setHostToPathList(props: HostToPathProps[]) {
|
|
11
|
-
this.props = props;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
static findHostPath(host: string): HostToPathProps | undefined {
|
|
15
|
-
for (let key in this.props) {
|
|
16
|
-
if (this.props[key].webPath && this.props[key].hosts.includes(host)) {
|
|
17
|
-
logger.debug(`Found ${host} in `, this.props[key].hosts);
|
|
18
|
-
return this.props[key];
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
for (let key in this.props) {
|
|
22
|
-
for (let domain in this.props[key].hosts) {
|
|
23
|
-
// if host is 'sub3.sub2.sub1.domain', it matches 'sub2.domain'
|
|
24
|
-
if (this.props[key].webPath && host.endsWith(this.props[key].hosts[domain])) {
|
|
25
|
-
logger.debug(`Found ${host} in `, this.props[key].hosts);
|
|
26
|
-
return this.props[key];
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
for (let key in this.props) {
|
|
31
|
-
if (this.props[key].webPath && this.props[key].hosts.length === 0) {
|
|
32
|
-
logger.debug(`Not found ${host} from any domains and use default app: ${this.props[key].appName}`);
|
|
33
|
-
return this.props[key];
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
1
|
+
// const request = require('request');
|
|
2
|
+
import { Logger } from '../lib';
|
|
3
|
+
import { HostToPathProps } from '../models';
|
|
4
|
+
|
|
5
|
+
const logger = new Logger('HostToPath');
|
|
6
|
+
export class HostToPath {
|
|
7
|
+
static props: HostToPathProps[] = [];
|
|
8
|
+
|
|
9
|
+
// this should be initialized before any request
|
|
10
|
+
static setHostToPathList(props: HostToPathProps[]) {
|
|
11
|
+
this.props = props;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
static findHostPath(host: string): HostToPathProps | undefined {
|
|
15
|
+
for (let key in this.props) {
|
|
16
|
+
if (this.props[key].webPath && this.props[key].hosts.includes(host)) {
|
|
17
|
+
logger.debug(`Found ${host} in `, this.props[key].hosts);
|
|
18
|
+
return this.props[key];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
for (let key in this.props) {
|
|
22
|
+
for (let domain in this.props[key].hosts) {
|
|
23
|
+
// if host is 'sub3.sub2.sub1.domain', it matches 'sub2.domain'
|
|
24
|
+
if (this.props[key].webPath && host.endsWith(this.props[key].hosts[domain])) {
|
|
25
|
+
logger.debug(`Found ${host} in `, this.props[key].hosts);
|
|
26
|
+
return this.props[key];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
for (let key in this.props) {
|
|
31
|
+
if (this.props[key].webPath && this.props[key].hosts.length === 0) {
|
|
32
|
+
logger.debug(`Not found ${host} from any domains and use default app: ${this.props[key].appName}`);
|
|
33
|
+
return this.props[key];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/app/index.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export * from './app-cache';
|
|
2
|
-
export * from './app-helper';
|
|
3
|
-
export * from './app-message';
|
|
4
|
-
export * from './app-shared-storage';
|
|
5
|
-
export * from './app-start';
|
|
6
|
-
export * from './cleanup-exit'
|
|
7
|
-
export * from './host-to-path';
|
|
8
|
-
export * from './process-dev-requests';
|
|
9
|
-
export * from './web-listener';
|
|
10
|
-
export * from './web-processor';
|
|
11
|
-
export * from './web-server';
|
|
1
|
+
export * from './app-cache';
|
|
2
|
+
export * from './app-helper';
|
|
3
|
+
export * from './app-message';
|
|
4
|
+
export * from './app-shared-storage';
|
|
5
|
+
export * from './app-start';
|
|
6
|
+
export * from './cleanup-exit';
|
|
7
|
+
export * from './host-to-path';
|
|
8
|
+
export * from './process-dev-requests';
|
|
9
|
+
export * from './web-listener';
|
|
10
|
+
export * from './web-processor';
|
|
11
|
+
export * from './web-server';
|