zcatalyst-cli 1.18.0-beta.0 → 1.18.0-beta.2
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/docs/command_needs/rc.toml +8 -8
- package/docs/commands/event/generate/job.toml +7 -0
- package/docs/endpoints/lib/job-scheduling.toml +3 -0
- package/docs/internal/command.toml +5 -0
- package/lib/appsail-utils.js +4 -10
- package/lib/authentication/index.js +1 -0
- package/lib/bin/catalyst.js +1 -1
- package/lib/command_needs/rc.js +8 -8
- package/lib/commands/appsail/add.js +2 -1
- package/lib/commands/client/setup.js +2 -1
- package/lib/commands/codelib/install.js +5 -2
- package/lib/commands/event/generate/index.js +2 -1
- package/lib/commands/event/generate/integ.js +2 -1
- package/lib/commands/event/generate/job.js +82 -0
- package/lib/commands/functions/add.js +2 -1
- package/lib/commands/functions/delete.js +2 -4
- package/lib/commands/functions/setup.js +2 -1
- package/lib/commands/functions/shell.js +1 -0
- package/lib/commands/index.js +3 -1
- package/lib/commands/init.js +10 -7
- package/lib/commands/login.js +1 -0
- package/lib/commands/logout.js +1 -0
- package/lib/commands/pull.js +1 -0
- package/lib/commands/serve.js +1 -1
- package/lib/commands/whoami.js +1 -0
- package/lib/deploy/features/appsail/index.js +42 -25
- package/lib/deploy/features/appsail/utils.js +4 -5
- package/lib/endpoints/index.js +10 -3
- package/lib/endpoints/lib/appsail.js +7 -1
- package/lib/endpoints/lib/job-scheduling.js +61 -0
- package/lib/express_middlewares/logger.js +2 -4
- package/lib/fn-utils/lib/common.js +2 -3
- package/lib/fn-utils/lib/java.js +1 -1
- package/lib/fn-utils/lib/python.js +2 -2
- package/lib/fn-watcher.js +1 -1
- package/lib/init/dependencies/python/ensure-python.js +6 -8
- package/lib/init/features/appsail/index.js +36 -26
- package/lib/init/features/client/index.js +2 -1
- package/lib/init/features/functions/index.js +4 -0
- package/lib/init/features/functions/languages/python.js +21 -5
- package/lib/init/features/project.js +5 -15
- package/lib/internal/api.js +25 -6
- package/lib/internal/command.js +30 -6
- package/lib/migration/index.js +4 -2
- package/lib/optional-import.js +3 -2
- package/lib/prompt/types/file-path.js +1 -1
- package/lib/prompt/types/tree.js +3 -3
- package/lib/serve/features/appsail.js +2 -3
- package/lib/serve/index.js +1 -2
- package/lib/serve/server/index.js +8 -9
- package/lib/serve/server/lib/appsail/index.js +29 -35
- package/lib/serve/server/lib/java/aio_server/lib/catalyst-cli-java-runtime-1.0.0.jar +0 -0
- package/lib/serve/server/lib/java/aio_server/lib/catalyst-function-sdk-1.0.0.jar +0 -0
- package/lib/serve/server/lib/java/aio_server/lib/catalyst-java-runtime-1.0.0.jar +0 -0
- package/lib/serve/server/lib/java/index.js +2 -2
- package/lib/serve/server/lib/master/appsail.js +53 -0
- package/lib/serve/server/lib/master/functions.js +34 -0
- package/lib/serve/server/lib/master/index.js +155 -0
- package/lib/{express_middlewares/unknownReqProxy.js → serve/server/lib/master/unknown-req-proxy.js} +4 -7
- package/lib/serve/server/lib/master/utils.js +130 -0
- package/lib/serve/server/lib/master/web-client.js +39 -0
- package/lib/serve/server/lib/node/index.js +3 -3
- package/lib/serve/server/lib/python/index.js +3 -3
- package/lib/shell/dependencies/invoker/bio/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
- package/lib/shell/dependencies/invoker/cron/java/JavacronInvoker.java +1 -1
- package/lib/shell/dependencies/invoker/cron/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
- package/lib/shell/dependencies/invoker/event/java/JavaeventInvoker.java +2 -1
- package/lib/shell/dependencies/invoker/event/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
- package/lib/shell/dependencies/invoker/event/node.mjs +1 -0
- package/lib/shell/dependencies/invoker/integ/java/JavaintegInvoker.java +14 -0
- package/lib/shell/dependencies/invoker/integ/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
- package/lib/shell/dependencies/invoker/integ/node.mjs +13 -0
- package/lib/shell/dependencies/invoker/job/java/JavajobInvoker.java +268 -0
- package/lib/shell/dependencies/invoker/job/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
- package/lib/shell/dependencies/invoker/job/java/lib/org.json.jar +0 -0
- package/lib/shell/dependencies/invoker/job/node.mjs +93 -0
- package/lib/shell/dependencies/local-function.js +121 -13
- package/lib/shell/index.js +7 -1
- package/lib/shell/prepare/languages/index.js +4 -4
- package/lib/shell/prepare/languages/java.js +1 -2
- package/lib/shell/prepare/languages/python.js +10 -16
- package/lib/throbber/index.js +6 -1
- package/lib/userConfig.js +7 -1
- package/lib/util_modules/config/index.js +1 -1
- package/lib/util_modules/config/lib/{appSail.js → appsail.js} +60 -10
- package/lib/util_modules/config/lib/client.js +6 -8
- package/lib/util_modules/config/lib/functions.js +6 -8
- package/lib/util_modules/constants/lib/default.js +9 -9
- package/lib/util_modules/constants/lib/fn-type.js +2 -1
- package/lib/util_modules/constants/lib/needed-scopes.js +53 -44
- package/lib/util_modules/constants/lib/placeholders.js +6 -0
- package/lib/util_modules/constants/lib/ref-mapping.js +2 -1
- package/lib/util_modules/constants/lib/remote-mapping.js +2 -1
- package/lib/util_modules/constants/lib/scopes.js +5 -1
- package/lib/util_modules/constants/lib/template.js +9 -4
- package/lib/util_modules/constants/lib/urls.js +8 -0
- package/lib/util_modules/fs/lib/async.js +14 -4
- package/lib/util_modules/fs/lib/sync.js +12 -1
- package/lib/util_modules/server.js +2 -4
- package/lib/winston.js +17 -11
- package/package.json +1 -1
- package/templates/event/job.json +30 -0
- package/templates/init/functions/java/job/.classpath +6 -0
- package/templates/init/functions/java/job/.project +17 -0
- package/templates/init/functions/java/job/catalyst-config.json +11 -0
- package/templates/init/functions/java/job/sample.java +34 -0
- package/templates/init/functions/node/aio/package.json +1 -1
- package/templates/init/functions/node/aio/sample.js +7 -0
- package/templates/init/functions/node/bio/package.json +1 -1
- package/templates/init/functions/node/bio/sample.js +5 -0
- package/templates/init/functions/node/bio/types/basicio.d.ts +57 -0
- package/templates/init/functions/node/cron/package.json +1 -1
- package/templates/init/functions/node/cron/sample.js +5 -0
- package/templates/init/functions/node/cron/types/cron.d.ts +64 -0
- package/templates/init/functions/node/event/package.json +1 -1
- package/templates/init/functions/node/event/sample.js +11 -8
- package/templates/init/functions/node/event/types/event.d.ts +82 -0
- package/templates/init/functions/node/integ/cliq/package.json +1 -1
- package/templates/init/functions/node/integ/convokraft/package.json +1 -1
- package/templates/init/functions/node/{stream → job}/catalyst-config.json +3 -2
- package/templates/init/functions/node/{stream → job}/package.json +1 -1
- package/templates/init/functions/node/job/sample.js +27 -0
- package/templates/init/functions/node/job/types/job.d.ts +62 -0
- package/templates/init/functions/python/job/catalyst-config.json +11 -0
- package/templates/init/functions/python/job/requirements.txt +1 -0
- package/templates/init/functions/python/job/sample.py +22 -0
- package/templates/init.txt +13 -0
- package/lib/serve/server/lib/master.js +0 -326
- package/templates/init/functions/node/stream/sample.js +0 -15
|
@@ -1,326 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const express_1 = __importDefault(require("express"));
|
|
16
|
-
const http_1 = require("http");
|
|
17
|
-
const error_1 = __importDefault(require("../../../error"));
|
|
18
|
-
const apig_matcher_1 = __importDefault(require("../../../express_middlewares/apig-matcher"));
|
|
19
|
-
const auth_checker_1 = __importDefault(require("../../../express_middlewares/auth-checker"));
|
|
20
|
-
const authenticator_1 = __importDefault(require("../../../express_middlewares/authenticator"));
|
|
21
|
-
const cookie_parser_1 = __importDefault(require("../../../express_middlewares/cookie-parser"));
|
|
22
|
-
const error_handler_1 = __importDefault(require("../../../express_middlewares/error-handler"));
|
|
23
|
-
const logger_1 = __importDefault(require("../../../express_middlewares/logger"));
|
|
24
|
-
const project_1 = __importDefault(require("../../../express_middlewares/project"));
|
|
25
|
-
const unknownReqProxy_1 = __importDefault(require("../../../express_middlewares/unknownReqProxy"));
|
|
26
|
-
const url_rewriter_1 = __importDefault(require("../../../express_middlewares/url-rewriter"));
|
|
27
|
-
const runtime_store_1 = __importDefault(require("../../../runtime-store"));
|
|
28
|
-
const constants_1 = require("../../../util_modules/constants");
|
|
29
|
-
const js_1 = require("../../../util_modules/js");
|
|
30
|
-
const logger_2 = require("../../../util_modules/logger");
|
|
31
|
-
const project_2 = require("../../../util_modules/project");
|
|
32
|
-
const option_1 = require("../../../util_modules/option");
|
|
33
|
-
const server_js_1 = require("../../../util_modules/server.js");
|
|
34
|
-
const http_proxy_1 = require("http-proxy");
|
|
35
|
-
const appsail_utils_1 = require("../../../appsail-utils");
|
|
36
|
-
const removeSecure = (str) => str.replace(/;\s?Secure/i, '').replace(/;\s?SameSite=None/i, '');
|
|
37
|
-
const redirectByAuth = (req, res, redirectUrl) => {
|
|
38
|
-
if (req.headers['x-zc-user-cred-token'] === undefined) {
|
|
39
|
-
res.writeHead(302, { Location: redirectUrl });
|
|
40
|
-
res.end();
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
res.writeHead(302, { Location: '/app/' });
|
|
44
|
-
res.end();
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
const proxyResponseHandler = (systemRoutes) => (proxyRes, req, res) => {
|
|
48
|
-
if (!req.url) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
if (req.url.startsWith('/oauthorize')) {
|
|
52
|
-
const set = proxyRes.headers['set-cookie'];
|
|
53
|
-
if (set) {
|
|
54
|
-
const result = Array.isArray(set) ? set.map(removeSecure) : removeSecure(set);
|
|
55
|
-
proxyRes.headers['set-cookie'] = result;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
else if (req.url.startsWith('/baas') || req.url.startsWith('/__catalyst')) {
|
|
59
|
-
if (req.url.includes('/signin-redirect')) {
|
|
60
|
-
if (systemRoutes === undefined) {
|
|
61
|
-
redirectByAuth(req, res, '/app/local-redirect');
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
const sourceRedirectUrl = Object.keys(systemRoutes).find((sourceUrl) => {
|
|
65
|
-
const methodByConfig = systemRoutes ? systemRoutes[sourceUrl] : undefined;
|
|
66
|
-
if (methodByConfig) {
|
|
67
|
-
return !!Object.values(methodByConfig).find((config) => {
|
|
68
|
-
return config.name === 'Login Redirect';
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
return false;
|
|
72
|
-
});
|
|
73
|
-
if (sourceRedirectUrl === undefined) {
|
|
74
|
-
res.end('INVALID_URL');
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
redirectByAuth(req, res, sourceRedirectUrl);
|
|
78
|
-
}
|
|
79
|
-
else if (req.url.includes('/logout')) {
|
|
80
|
-
const set = proxyRes.headers['set-cookie'];
|
|
81
|
-
if (set) {
|
|
82
|
-
const result = set.map((cookie) => cookie.replace(new RegExp('Domain=[\\S^;]*', 'g'), 'Domain=localhost;'));
|
|
83
|
-
proxyRes.headers['set-cookie'] = result;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
else if (req.url.startsWith('/accounts') && req.url.includes('/signin')) {
|
|
88
|
-
const set = proxyRes.headers['set-cookie'];
|
|
89
|
-
set
|
|
90
|
-
? set.push('IAM_TEST_COOKIE=IAM_TEST_COOKIE; Domain=localhost; Path=/')
|
|
91
|
-
: ['IAM_TEST_COOKIE=IAM_TEST_COOKIE; Domain=localhost; Path=/'];
|
|
92
|
-
proxyRes.headers['set-cookie'] = set;
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
function spinUpMaster(listenPort, otherServerDetails) {
|
|
96
|
-
var _a, _b, _c, _d;
|
|
97
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
-
const projectDetails = ((_b = (_a = otherServerDetails.appSail) === null || _a === void 0 ? void 0 : _a.at(0)) === null || _b === void 0 ? void 0 : _b.target) !== undefined
|
|
99
|
-
? {
|
|
100
|
-
id: (0, project_2.getProjectId)(),
|
|
101
|
-
domain_prefix: (0, appsail_utils_1.getDomainPrefix)((_c = otherServerDetails.appSail.at(0)) === null || _c === void 0 ? void 0 : _c.target),
|
|
102
|
-
domain: constants_1.ORIGIN.appSailDomain.replace('https://', ''),
|
|
103
|
-
key: (0, project_2.getDomainKey)(),
|
|
104
|
-
env_name: (0, project_2.getEnvName)()
|
|
105
|
-
}
|
|
106
|
-
: {
|
|
107
|
-
id: (0, project_2.getProjectId)(),
|
|
108
|
-
domain_prefix: (0, project_2.getDomainPrefix)(),
|
|
109
|
-
domain: constants_1.ORIGIN.app.replace('https://', ''),
|
|
110
|
-
key: (0, project_2.getDomainKey)(),
|
|
111
|
-
env_name: (0, project_2.getEnvName)()
|
|
112
|
-
};
|
|
113
|
-
const rules = runtime_store_1.default.get('context.apig.local.config', -1);
|
|
114
|
-
const customProxyUrl = (0, option_1.getOptionValue)('proxy');
|
|
115
|
-
const app = (0, express_1.default)();
|
|
116
|
-
let systemRoutes;
|
|
117
|
-
const nonApigURL = ['/accounts', '/clientoauth', '/_wms', '/wmssrv'];
|
|
118
|
-
app.use((0, logger_1.default)((_d = otherServerDetails.appSail) === null || _d === void 0 ? void 0 : _d.at(0)));
|
|
119
|
-
app.use(cookie_parser_1.default);
|
|
120
|
-
app.use((0, project_1.default)(projectDetails));
|
|
121
|
-
app.use(authenticator_1.default);
|
|
122
|
-
app.use(nonApigURL, (req, res) => {
|
|
123
|
-
req.url = req.originalUrl;
|
|
124
|
-
(0, unknownReqProxy_1.default)(proxy, customProxyUrl)(req, res);
|
|
125
|
-
});
|
|
126
|
-
app.use('*/.catalyst%2Freload-script.js', (req, res) => {
|
|
127
|
-
var _a;
|
|
128
|
-
req.url = '/.catalyst%2Freload-script.js';
|
|
129
|
-
(_a = otherServerDetails.client) === null || _a === void 0 ? void 0 : _a.forEach((clientDetails) => {
|
|
130
|
-
const appTarget = `http://127.0.0.1:${clientDetails.httpPort}/app/`;
|
|
131
|
-
proxy.web(req, res, {
|
|
132
|
-
target: appTarget,
|
|
133
|
-
changeOrigin: true
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
if (rules !== -1) {
|
|
138
|
-
for (const [sourceURL, methodByConfig] of Object.entries(rules)) {
|
|
139
|
-
const router = app.route(sourceURL);
|
|
140
|
-
for (const [method, config] of Object.entries(methodByConfig)) {
|
|
141
|
-
if (config.system) {
|
|
142
|
-
if (systemRoutes === undefined) {
|
|
143
|
-
systemRoutes = {};
|
|
144
|
-
}
|
|
145
|
-
js_1.JS.set(systemRoutes, [sourceURL, method], config);
|
|
146
|
-
}
|
|
147
|
-
router[method]((req, res, next) => {
|
|
148
|
-
if (res.locals.apigRules === undefined) {
|
|
149
|
-
res.locals.apigRules = [];
|
|
150
|
-
}
|
|
151
|
-
res.locals.apigRules.push(Object.assign({ source_endpoint: sourceURL, params: req.params }, config));
|
|
152
|
-
next();
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
app.use('/', apig_matcher_1.default, auth_checker_1.default, url_rewriter_1.default);
|
|
157
|
-
}
|
|
158
|
-
const proxy = (0, http_proxy_1.createProxyServer)({
|
|
159
|
-
hostRewrite: `localhost:${listenPort}`,
|
|
160
|
-
protocolRewrite: 'http'
|
|
161
|
-
})
|
|
162
|
-
.on('error', (err, req, res) => {
|
|
163
|
-
if (res.writableEnded) {
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
if (res instanceof http_1.ServerResponse) {
|
|
167
|
-
res.writeHead(502, { 'Content-Type': 'json' });
|
|
168
|
-
}
|
|
169
|
-
res.end(JSON.stringify({ error: 'unable to serve the request' }));
|
|
170
|
-
console.log();
|
|
171
|
-
console.log('Unable to reach the servers to serve the request: ', req.url);
|
|
172
|
-
console.error(err);
|
|
173
|
-
})
|
|
174
|
-
.on('econnreset', (err, req, res, targetUrl) => {
|
|
175
|
-
if (res.writableEnded) {
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
if (res instanceof http_1.ServerResponse) {
|
|
179
|
-
res.writeHead(502, { 'Content-Type': 'json' });
|
|
180
|
-
}
|
|
181
|
-
res.end(JSON.stringify({ error: 'unable to serve the request. ECONNRESET.' }));
|
|
182
|
-
console.log();
|
|
183
|
-
console.log('Connection reset while trying to serve the request ', req.url);
|
|
184
|
-
(0, logger_2.debug)('Connection reset from target URL : ', targetUrl);
|
|
185
|
-
console.error(err);
|
|
186
|
-
})
|
|
187
|
-
.on('proxyRes', proxyResponseHandler(systemRoutes))
|
|
188
|
-
.on('close', () => (0, logger_2.debug)('proxy closed'));
|
|
189
|
-
const proxyDestroyer = new server_js_1.ConnectionDestroyer(proxy);
|
|
190
|
-
Object.keys(otherServerDetails).forEach((targ) => {
|
|
191
|
-
var _a, _b, _c, _d;
|
|
192
|
-
switch (targ) {
|
|
193
|
-
case 'client': {
|
|
194
|
-
(_a = otherServerDetails.client) === null || _a === void 0 ? void 0 : _a.forEach((clientDetails) => {
|
|
195
|
-
const appTarget = `http://127.0.0.1:${clientDetails.httpPort}/app/`;
|
|
196
|
-
app.use('/app', (req, res) => {
|
|
197
|
-
const target = clientDetails.target;
|
|
198
|
-
if (req.url === '/' && target.homepage.includes('/__catalyst')) {
|
|
199
|
-
req.url = target.homepage;
|
|
200
|
-
(0, unknownReqProxy_1.default)(proxy, customProxyUrl)(req, res);
|
|
201
|
-
}
|
|
202
|
-
else if (req.url.startsWith('/local-redirect') && target.login_redirect) {
|
|
203
|
-
const isUrl = target.login_redirect.startsWith('/');
|
|
204
|
-
if (isUrl) {
|
|
205
|
-
res.redirect(target.login_redirect);
|
|
206
|
-
}
|
|
207
|
-
else {
|
|
208
|
-
res.redirect('/app/' + target.login_redirect);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
else {
|
|
212
|
-
proxy.web(req, res, {
|
|
213
|
-
target: appTarget,
|
|
214
|
-
changeOrigin: true
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
const appTargetUrl = new URL(appTarget);
|
|
219
|
-
appTargetUrl.pathname = '';
|
|
220
|
-
appTargetUrl.protocol = 'ws';
|
|
221
|
-
app.addListener('upgrade', (...upgradeParam) => {
|
|
222
|
-
proxy.ws(upgradeParam[0], upgradeParam[1], upgradeParam[2], {
|
|
223
|
-
target: appTargetUrl.href,
|
|
224
|
-
ws: true,
|
|
225
|
-
changeOrigin: true
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
break;
|
|
230
|
-
}
|
|
231
|
-
case 'server': {
|
|
232
|
-
(_b = otherServerDetails.server) === null || _b === void 0 ? void 0 : _b.forEach((serverDetail) => {
|
|
233
|
-
var _a;
|
|
234
|
-
app.use('/server/' + ((_a = serverDetail.target) === null || _a === void 0 ? void 0 : _a.name), (req, res) => {
|
|
235
|
-
proxy.web(req, res, {
|
|
236
|
-
target: `http://127.0.0.1:${serverDetail.httpPort}`
|
|
237
|
-
});
|
|
238
|
-
});
|
|
239
|
-
});
|
|
240
|
-
break;
|
|
241
|
-
}
|
|
242
|
-
case 'functions': {
|
|
243
|
-
(_c = otherServerDetails.functions) === null || _c === void 0 ? void 0 : _c.forEach((fnDetails) => {
|
|
244
|
-
const fnTarget = fnDetails.target;
|
|
245
|
-
app.use(`/server/${fnTarget.name}`, (req, res) => {
|
|
246
|
-
proxy.web(req, res, {
|
|
247
|
-
target: `http://127.0.0.1:${fnDetails.httpPort}${fnTarget.type === constants_1.FN_TYPE.basic
|
|
248
|
-
? `/server/${fnTarget.name}/execute`
|
|
249
|
-
: ''}`,
|
|
250
|
-
ws: true
|
|
251
|
-
});
|
|
252
|
-
});
|
|
253
|
-
app.use(`/baas/v1/project/:projectId/function/${fnTarget.name}`, (req, res) => {
|
|
254
|
-
proxy.web(req, res, {
|
|
255
|
-
target: `http://127.0.0.1:${fnDetails.httpPort}${fnTarget.type === constants_1.FN_TYPE.basic
|
|
256
|
-
? `/server/${fnTarget.name}/execute`
|
|
257
|
-
: ''}`,
|
|
258
|
-
ws: true
|
|
259
|
-
});
|
|
260
|
-
});
|
|
261
|
-
if (fnTarget.id) {
|
|
262
|
-
app.use(`/server/${fnTarget.id}`, (req, res) => {
|
|
263
|
-
proxy.web(req, res, {
|
|
264
|
-
target: `http://127.0.0.1:${fnDetails.httpPort}${fnTarget.type === constants_1.FN_TYPE.basic
|
|
265
|
-
? `/server/${fnTarget.id}/execute`
|
|
266
|
-
: ''}`,
|
|
267
|
-
ws: true
|
|
268
|
-
});
|
|
269
|
-
});
|
|
270
|
-
app.use(`/baas/v1/project/:projectId/function/${fnTarget.id}`, (req, res) => {
|
|
271
|
-
proxy.web(req, res, {
|
|
272
|
-
target: `http://127.0.0.1:${fnDetails.httpPort}${fnTarget.type === constants_1.FN_TYPE.basic
|
|
273
|
-
? `/server/${fnTarget.id}/execute`
|
|
274
|
-
: ''}`,
|
|
275
|
-
ws: true
|
|
276
|
-
});
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
});
|
|
280
|
-
break;
|
|
281
|
-
}
|
|
282
|
-
case 'appSail': {
|
|
283
|
-
(_d = otherServerDetails.appSail) === null || _d === void 0 ? void 0 : _d.forEach((appSailDetails) => {
|
|
284
|
-
app.use('/', (req, res) => {
|
|
285
|
-
var _a;
|
|
286
|
-
if ((_a = req.url) === null || _a === void 0 ? void 0 : _a.includes('/__catalyst/sdk/init.js')) {
|
|
287
|
-
(0, unknownReqProxy_1.default)(proxy, customProxyUrl)(req, res);
|
|
288
|
-
}
|
|
289
|
-
else {
|
|
290
|
-
proxy.web(req, res, {
|
|
291
|
-
target: `http://127.0.0.1:${appSailDetails.target.port
|
|
292
|
-
.appsail}`,
|
|
293
|
-
ws: true
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
});
|
|
297
|
-
});
|
|
298
|
-
break;
|
|
299
|
-
}
|
|
300
|
-
default:
|
|
301
|
-
throw new error_1.default('Unknown type provided to master server ' + targ, {
|
|
302
|
-
exit: 2
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
});
|
|
306
|
-
app.use('/', (0, unknownReqProxy_1.default)(proxy, customProxyUrl));
|
|
307
|
-
app.use(error_handler_1.default);
|
|
308
|
-
const expressServer = app.listen(listenPort, '127.0.0.1').on('error', (err) => {
|
|
309
|
-
if (proxy) {
|
|
310
|
-
proxyDestroyer.destroy();
|
|
311
|
-
}
|
|
312
|
-
console.error(err);
|
|
313
|
-
});
|
|
314
|
-
const expressDestroyer = new server_js_1.ConnectionDestroyer(expressServer);
|
|
315
|
-
expressServer.maxConnections = 100;
|
|
316
|
-
process.on('SIGINT', () => expressDestroyer.destroy(false));
|
|
317
|
-
expressServer.on('close', () => __awaiter(this, void 0, void 0, function* () {
|
|
318
|
-
yield proxyDestroyer.destroy().catch((err) => (0, logger_2.debug)(err));
|
|
319
|
-
}));
|
|
320
|
-
expressServer.on('upgrade', (...upgradeParam) => {
|
|
321
|
-
app.emit('upgrade', ...upgradeParam);
|
|
322
|
-
});
|
|
323
|
-
return expressServer;
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
exports.default = spinUpMaster;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
module.exports = (inputStream, outputStream, context) => {
|
|
2
|
-
console.log('Hello from {{_MAIN_}}');
|
|
3
|
-
|
|
4
|
-
// inputStream.getContentType();
|
|
5
|
-
// inputStream.getContentLength();
|
|
6
|
-
// inputStream.getParameter('name');
|
|
7
|
-
|
|
8
|
-
let response = 'stream response';
|
|
9
|
-
outputStream.setContentType('text/plain');
|
|
10
|
-
outputStream.setStatus(201);
|
|
11
|
-
outputStream.setContentLength(response.length);
|
|
12
|
-
outputStream.getStream().write(response);
|
|
13
|
-
|
|
14
|
-
context.close();
|
|
15
|
-
};
|