@sassoftware/viya-serverjs 0.6.2 → 0.6.3-0
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/.env +1 -0
- package/autoStart.js +6 -0
- package/cli.js +20 -2
- package/lib/iService.js +217 -194
- package/lib/index.js +101 -39
- package/package.json +1 -1
- package/src/iService.js +11 -3
- package/src/index.js +20 -11
package/.env
CHANGED
package/autoStart.js
ADDED
package/cli.js
CHANGED
|
@@ -4,7 +4,25 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
import api from './lib/index.js';
|
|
8
|
+
import autoStart from './autoStart.js';
|
|
9
|
+
|
|
8
10
|
console.log('Starting the cli for @sassoftware/viya-serverjs');
|
|
9
11
|
let userCache = {};
|
|
10
|
-
|
|
12
|
+
|
|
13
|
+
api.asyncCore(null, true, 'app', null, userCache)
|
|
14
|
+
.then ((r) => {
|
|
15
|
+
console.log('core returned', r);
|
|
16
|
+
if (process.env.AUTOSTART && process.env.AUTOSTART.toUpperCase() === 'TRUE'){
|
|
17
|
+
console.log('Auto-starting the server as per AUTOSTART env variable');
|
|
18
|
+
autoStart(r).catch((err) => {
|
|
19
|
+
console.log('Error in autoStart', err);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return r;
|
|
23
|
+
})
|
|
24
|
+
.catch((err) => {
|
|
25
|
+
console.log('Error in core', err);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
|
package/lib/iService.js
CHANGED
|
@@ -47,202 +47,225 @@ var Vision = require('@hapi/vision');
|
|
|
47
47
|
var inert = require('@hapi/inert');
|
|
48
48
|
var selfsigned = require('selfsigned');
|
|
49
49
|
var os = require('os');
|
|
50
|
-
function iService(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
50
|
+
function iService(_x, _x2, _x3, _x4, _x5, _x6) {
|
|
51
|
+
return _iService.apply(this, arguments);
|
|
52
|
+
}
|
|
53
|
+
function _iService() {
|
|
54
|
+
_iService = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(userRouteTable, useDefault, asset, allAppEnv, serverMode, userCache) {
|
|
55
|
+
var init, r, _t;
|
|
56
|
+
return _regenerator().w(function (_context2) {
|
|
57
|
+
while (1) switch (_context2.p = _context2.n) {
|
|
58
|
+
case 0:
|
|
59
|
+
// process.env.APPHOST_ADDR = process.env.APPHOST;
|
|
60
|
+
init = /*#__PURE__*/function () {
|
|
61
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
62
|
+
var defaultMaxBytes, maxBytes, isSameSite, isSecure, https, _process$env$SAMESITE, _process$env$SAMESITE2, s1, s2, sConfig, hapiServer, nodeCacheOptions, storeCache, visionOptions, options, allRoutes, hh, msg;
|
|
63
|
+
return _regenerator().w(function (_context) {
|
|
64
|
+
while (1) switch (_context.n) {
|
|
65
|
+
case 0:
|
|
66
|
+
if (process.env.APPHOST === '*') {
|
|
67
|
+
process.env.APPHOST = os.hostname();
|
|
68
|
+
}
|
|
69
|
+
defaultMaxBytes = 10485760;
|
|
70
|
+
if (isNaN(process.env.PAYLOADMAXBYTES)) {
|
|
71
|
+
maxBytes = defaultMaxBytes;
|
|
72
|
+
} else {
|
|
73
|
+
maxBytes = Number(process.env.PAYLOADMAXBYTES);
|
|
74
|
+
}
|
|
75
|
+
isSameSite = 'Lax';
|
|
76
|
+
isSecure = false;
|
|
77
|
+
https = process.env.HTTPS || 'TRUE';
|
|
78
|
+
https = https.toUpperCase();
|
|
79
|
+
if (process.env.SAMESITE != null) {
|
|
80
|
+
_process$env$SAMESITE = process.env.SAMESITE.split(','), _process$env$SAMESITE2 = _slicedToArray(_process$env$SAMESITE, 2), s1 = _process$env$SAMESITE2[0], s2 = _process$env$SAMESITE2[1];
|
|
81
|
+
isSameSite = s1;
|
|
82
|
+
isSecure = s2 === 'secure' ? true : false;
|
|
83
|
+
if (https !== 'TRUE') {
|
|
84
|
+
isSecure = false;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
sConfig = {
|
|
88
|
+
port: process.env.APPPORT,
|
|
89
|
+
host: process.env.APPHOST,
|
|
90
|
+
state: {
|
|
91
|
+
isSameSite: isSameSite,
|
|
92
|
+
isSecure: isSecure
|
|
93
|
+
},
|
|
94
|
+
routes: {
|
|
95
|
+
payload: {
|
|
96
|
+
maxBytes: maxBytes
|
|
97
|
+
},
|
|
98
|
+
cors: {
|
|
99
|
+
origin: ['*'],
|
|
100
|
+
credentials: true,
|
|
101
|
+
"headers": ["Accept", "Authorization", "Content-Type", "If-None-Match", "Accept-language"]
|
|
102
|
+
/*
|
|
103
|
+
'Access-Control-Allow-Methods': ['GET', 'POST', 'OPTIONS'],
|
|
104
|
+
additionalHeaders : ['multipart/form-data', 'content-disposition'],
|
|
105
|
+
additionalExposedHeaders : ['location'],
|
|
106
|
+
*/
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
if (process.env.HAPIDEBUG === 'YES') {
|
|
111
|
+
sConfig.debug = {
|
|
112
|
+
request: '*'
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
debug(JSON.stringify(sConfig, null, 4));
|
|
116
|
+
if (https === 'TRUE') {
|
|
117
|
+
sConfig.tls = getCertificates();
|
|
118
|
+
debug('Setup of SSL certificates completed');
|
|
119
|
+
} else {
|
|
120
|
+
debug('Running with no SSL certificates');
|
|
121
|
+
}
|
|
122
|
+
if (asset !== null) {
|
|
123
|
+
sConfig.routes.files = {
|
|
124
|
+
relativeTo: asset
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
debug2("Application information: \n\t\tAPPLOC : ".concat(process.env.APPLOC, "\n\t\tAPPENTRY: ").concat(process.env.APPENTRY, "\n"));
|
|
128
|
+
hapiServer = Hapi.server(sConfig);
|
|
129
|
+
/*
|
|
130
|
+
const cache = hapiServer.cache({ segment: 'sid', expiresIn: 3 * 24 * 60 * 60 * 1000 });
|
|
131
|
+
hapiServer.app.cache = cache;
|
|
132
|
+
*/
|
|
133
|
+
nodeCacheOptions = {
|
|
134
|
+
stdTTL: 24 * 60 * 60 * 1000,
|
|
135
|
+
checkPeriod: 3600,
|
|
136
|
+
errorOnMissing: true,
|
|
137
|
+
useClones: false,
|
|
138
|
+
deleteOnExpire: true
|
|
139
|
+
};
|
|
140
|
+
storeCache = new NodeCache(nodeCacheOptions);
|
|
141
|
+
hapiServer.app.cache = storeCache;
|
|
134
142
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
143
|
+
// common plugins
|
|
144
|
+
visionOptions = {
|
|
145
|
+
engines: {
|
|
146
|
+
html: require('handlebars')
|
|
147
|
+
},
|
|
148
|
+
relativeTo: __dirname,
|
|
149
|
+
path: '.'
|
|
150
|
+
};
|
|
151
|
+
_context.n = 1;
|
|
152
|
+
return hapiServer.register(Vision);
|
|
153
|
+
case 1:
|
|
154
|
+
hapiServer.views(visionOptions);
|
|
155
|
+
_context.n = 2;
|
|
156
|
+
return hapiServer.register(inert);
|
|
157
|
+
case 2:
|
|
158
|
+
if (!(https === 'TRUE')) {
|
|
159
|
+
_context.n = 3;
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
_context.n = 3;
|
|
163
|
+
return hapiServer.register({
|
|
164
|
+
plugin: require('hapi-require-https'),
|
|
165
|
+
options: {}
|
|
166
|
+
});
|
|
167
|
+
case 3:
|
|
168
|
+
_context.n = 4;
|
|
169
|
+
return hapiServer.register(H202);
|
|
170
|
+
case 4:
|
|
171
|
+
// setup authentication related plugins
|
|
172
|
+
options = {
|
|
173
|
+
serverMode: serverMode,
|
|
174
|
+
authFlow: process.env.AUTHFLOW,
|
|
175
|
+
host: process.env.VIYA_SERVER,
|
|
176
|
+
isSameSite: isSameSite,
|
|
177
|
+
isSecure: isSecure,
|
|
178
|
+
ns: allAppEnv.LOGONPAYLOAD != null ? allAppEnv.LOGONPAYLOAD.ns : null,
|
|
179
|
+
nsHost: allAppEnv.LOGONPAYLOAD != null ? allAppEnv.LOGONPAYLOAD.nsHost : null,
|
|
180
|
+
redirect: process.env.REDIRECT,
|
|
181
|
+
clientId: process.env.CLIENTID,
|
|
182
|
+
clientSecret: process.env.CLIENTSECRET,
|
|
183
|
+
redirectTo: "/".concat(process.env.APPNAME, "/logon"),
|
|
184
|
+
allAppEnv: allAppEnv,
|
|
185
|
+
useHapiCookie: true,
|
|
186
|
+
appName: process.env.APPNAME,
|
|
187
|
+
appHost: process.env.APPHOST,
|
|
188
|
+
appPort: process.env.APPPORT,
|
|
189
|
+
userRouteTable: userRouteTable,
|
|
190
|
+
useDefault: useDefault,
|
|
191
|
+
/* not used - left here for potential reuse */
|
|
192
|
+
userCache: userCache || {},
|
|
193
|
+
https: https,
|
|
194
|
+
authDefault: false,
|
|
195
|
+
/* set later in setDefaultRoutes */
|
|
196
|
+
authLogon: false /* set later in setDefaultRoutes */
|
|
197
|
+
};
|
|
198
|
+
debug2('Options', options);
|
|
199
|
+
if (!(process.env.AUTHFLOW != null)) {
|
|
200
|
+
_context.n = 6;
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
_context.n = 5;
|
|
204
|
+
return (0, _setupAuth["default"])(hapiServer, options);
|
|
205
|
+
case 5:
|
|
206
|
+
if (process.env.PREAUTH === 'YES') {
|
|
207
|
+
console.log('Preauth enabled');
|
|
208
|
+
hapiServer.ext('onPreAuth', function (request, h) {
|
|
209
|
+
debugger;
|
|
210
|
+
if (!request.auth.isAuthenticated && !request.path.startsWith("/login")) {
|
|
211
|
+
var redirectTo = "".concat(request.path, "?").concat(new URLSearchParams(request.query).toString());
|
|
212
|
+
console.log('Redirect to login', {
|
|
213
|
+
redirectTo: redirectTo
|
|
214
|
+
});
|
|
215
|
+
debugger;
|
|
216
|
+
return h.redirect("/login").takeover();
|
|
217
|
+
}
|
|
218
|
+
return h["continue"];
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
case 6:
|
|
222
|
+
//
|
|
223
|
+
// Start server
|
|
224
|
+
//
|
|
225
|
+
// eslint-disable-next-line no-unused-vars
|
|
226
|
+
allRoutes = hapiServer.table();
|
|
227
|
+
_context.n = 7;
|
|
228
|
+
return hapiServer.start();
|
|
229
|
+
case 7:
|
|
230
|
+
hh = hapiServer.info.uri;
|
|
231
|
+
hh = hh.replace(/0.0.0.0/, 'localhost');
|
|
232
|
+
console.log('====================================================================================');
|
|
233
|
+
console.log('Server Start Time: ', Date());
|
|
234
|
+
msg = options.serverMode === 'app' ? "Visit ".concat(hh, "/").concat(process.env.APPNAME, " to access application") : "Visit ".concat(hh, "/").concat(process.env.APPNAME, "/api to access swagger");
|
|
235
|
+
console.log('\x1b[1m%s\x1b[0m', msg);
|
|
236
|
+
console.log('NOTE: If running in container use the exported port');
|
|
237
|
+
process.env.APPSERVER = "".concat(hh, "/").concat(process.env.APPNAME);
|
|
238
|
+
process.env.HEALTH = 'true';
|
|
239
|
+
console.log('====================================================================================');
|
|
240
|
+
return _context.a(2, "".concat(hh, "/").concat(process.env.APPNAME));
|
|
209
241
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
return function init() {
|
|
238
|
-
return _ref.apply(this, arguments);
|
|
239
|
-
};
|
|
240
|
-
}();
|
|
241
|
-
process.on('unhandledRejection', function (err) {
|
|
242
|
-
console.log(err);
|
|
243
|
-
process.exit(1);
|
|
244
|
-
});
|
|
245
|
-
init();
|
|
242
|
+
}, _callee);
|
|
243
|
+
}));
|
|
244
|
+
return function init() {
|
|
245
|
+
return _ref.apply(this, arguments);
|
|
246
|
+
};
|
|
247
|
+
}();
|
|
248
|
+
process.on('unhandledRejection', function (err) {
|
|
249
|
+
console.log(err);
|
|
250
|
+
process.exit(1);
|
|
251
|
+
});
|
|
252
|
+
_context2.p = 1;
|
|
253
|
+
_context2.n = 2;
|
|
254
|
+
return init();
|
|
255
|
+
case 2:
|
|
256
|
+
r = _context2.v;
|
|
257
|
+
return _context2.a(2, r);
|
|
258
|
+
case 3:
|
|
259
|
+
_context2.p = 3;
|
|
260
|
+
_t = _context2.v;
|
|
261
|
+
console.log('Error starting server', _t);
|
|
262
|
+
return _context2.a(2, false);
|
|
263
|
+
case 4:
|
|
264
|
+
return _context2.a(2);
|
|
265
|
+
}
|
|
266
|
+
}, _callee2, null, [[1, 3]]);
|
|
267
|
+
}));
|
|
268
|
+
return _iService.apply(this, arguments);
|
|
246
269
|
}
|
|
247
270
|
function getCertificates() {
|
|
248
271
|
var tlsdir = process.env.SSLCERT;
|
package/lib/index.js
CHANGED
|
@@ -9,7 +9,10 @@ var _readCerts = _interopRequireDefault(require("./readCerts"));
|
|
|
9
9
|
var _yargs = _interopRequireDefault(require("yargs"));
|
|
10
10
|
var _helpers = require("yargs/helpers");
|
|
11
11
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
12
|
-
|
|
12
|
+
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
13
|
+
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
|
|
14
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
15
|
+
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; } /*
|
|
13
16
|
* ------------------------------------------------------------------------------------
|
|
14
17
|
* * Copyright (c) SAS Institute Inc.
|
|
15
18
|
* * Licensed under the Apache License, Version 2.0 (the 'License');
|
|
@@ -26,43 +29,106 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default":
|
|
|
26
29
|
* ----------------------------------------------------------------------------------------
|
|
27
30
|
*
|
|
28
31
|
*/
|
|
29
|
-
|
|
30
32
|
var debug = require("debug")("startup");
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
useDefault = true;
|
|
40
|
-
}
|
|
41
|
-
console.log("Initialization started ============================================================");
|
|
42
|
-
console.log("version: 2, Build Date: ", Date());
|
|
43
|
-
console.log("\nCommand Line Configuration:\n Dockerfile: ".concat(docker, "\n env file : ").concat(env, "\n appenv : ").concat(appenv, "\n customize : ").concat(customize != null, "\n "));
|
|
44
|
-
iapp(null, env, docker, uTable, useDefault, serverMode, customize, userCache);
|
|
33
|
+
exports.core = function () {
|
|
34
|
+
icore().then(function (r) {
|
|
35
|
+
console.log('icore returned', r);
|
|
36
|
+
return r;
|
|
37
|
+
})["catch"](function (err) {
|
|
38
|
+
console.log('Error in icore', err);
|
|
39
|
+
return null;
|
|
40
|
+
});
|
|
45
41
|
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
42
|
+
exports.asyncCore = icore;
|
|
43
|
+
function icore(_x, _x2, _x3, _x4, _x5) {
|
|
44
|
+
return _icore.apply(this, arguments);
|
|
45
|
+
}
|
|
46
|
+
function _icore() {
|
|
47
|
+
_icore = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(uTable, useDefault, serverMode, customize, userCache) {
|
|
48
|
+
var argv, env, appenv, docker;
|
|
49
|
+
return _regenerator().w(function (_context) {
|
|
50
|
+
while (1) switch (_context.n) {
|
|
51
|
+
case 0:
|
|
52
|
+
argv = (0, _yargs["default"])((0, _helpers.hideBin)(process.argv)).argv;
|
|
53
|
+
env = argv.env == null ? null : argv.env;
|
|
54
|
+
appenv = argv.appenv == null ? null : argv.appenv;
|
|
55
|
+
docker = argv.docker == null ? null : argv.docker; //process.env.SERVERMODE = serverMode !== null ? "api" : "app";
|
|
56
|
+
if (useDefault == null) {
|
|
57
|
+
useDefault = true;
|
|
58
|
+
}
|
|
59
|
+
console.log("Initialization started ============================================================");
|
|
60
|
+
console.log("version: 2, Build Date: ", Date());
|
|
61
|
+
console.log("\nCommand Line Configuration:\n Dockerfile: ".concat(docker, "\n env file : ").concat(env, "\n appenv : ").concat(appenv, "\n customize : ").concat(customize != null, "\n "));
|
|
62
|
+
_context.n = 1;
|
|
63
|
+
return iapp(null, env, docker, uTable, useDefault, serverMode, customize, userCache);
|
|
64
|
+
case 1:
|
|
65
|
+
return _context.a(2, _context.v);
|
|
60
66
|
}
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
67
|
+
}, _callee);
|
|
68
|
+
}));
|
|
69
|
+
return _icore.apply(this, arguments);
|
|
70
|
+
}
|
|
71
|
+
;
|
|
72
|
+
function iapp(_x6, _x7, _x8, _x9, _x0, _x1, _x10, _x11) {
|
|
73
|
+
return _iapp.apply(this, arguments);
|
|
74
|
+
}
|
|
75
|
+
function _iapp() {
|
|
76
|
+
_iapp = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(appSrc, rafEnv, dockerFile, uTable, useDefault, serverMode, customize, userCache) {
|
|
77
|
+
var asset, appEnv;
|
|
78
|
+
return _regenerator().w(function (_context3) {
|
|
79
|
+
while (1) switch (_context3.n) {
|
|
80
|
+
case 0:
|
|
81
|
+
asset = setup(rafEnv, dockerFile);
|
|
82
|
+
if (appSrc == null) {
|
|
83
|
+
appSrc = process.env.APPENV == null ? null : process.env.APPENV;
|
|
84
|
+
}
|
|
85
|
+
if (!(appSrc != null)) {
|
|
86
|
+
_context3.n = 1;
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
console.log("appSrc", "+".concat(appSrc, "+"));
|
|
90
|
+
createPayload(appSrc, /*#__PURE__*/function () {
|
|
91
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(err, r) {
|
|
92
|
+
return _regenerator().w(function (_context2) {
|
|
93
|
+
while (1) switch (_context2.n) {
|
|
94
|
+
case 0:
|
|
95
|
+
if (!err) {
|
|
96
|
+
_context2.n = 1;
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
console.log(err);
|
|
100
|
+
console.log("createPayload failed");
|
|
101
|
+
process.exit(1);
|
|
102
|
+
_context2.n = 3;
|
|
103
|
+
break;
|
|
104
|
+
case 1:
|
|
105
|
+
_context2.n = 2;
|
|
106
|
+
return (0, _iService["default"])(uTable, useDefault, asset, r, serverMode, customize, userCache);
|
|
107
|
+
case 2:
|
|
108
|
+
return _context2.a(2, _context2.v);
|
|
109
|
+
case 3:
|
|
110
|
+
return _context2.a(2);
|
|
111
|
+
}
|
|
112
|
+
}, _callee2);
|
|
113
|
+
}));
|
|
114
|
+
return function (_x12, _x13) {
|
|
115
|
+
return _ref.apply(this, arguments);
|
|
116
|
+
};
|
|
117
|
+
}());
|
|
118
|
+
_context3.n = 3;
|
|
119
|
+
break;
|
|
120
|
+
case 1:
|
|
121
|
+
appEnv = getAllEnv({});
|
|
122
|
+
_context3.n = 2;
|
|
123
|
+
return (0, _iService["default"])(uTable, useDefault, asset, appEnv, serverMode, customize, userCache);
|
|
124
|
+
case 2:
|
|
125
|
+
return _context3.a(2, _context3.v);
|
|
126
|
+
case 3:
|
|
127
|
+
return _context3.a(2);
|
|
128
|
+
}
|
|
129
|
+
}, _callee3);
|
|
130
|
+
}));
|
|
131
|
+
return _iapp.apply(this, arguments);
|
|
66
132
|
}
|
|
67
133
|
function setup(rafEnv, dockerFile) {
|
|
68
134
|
(0, _config["default"])(rafEnv, dockerFile);
|
|
@@ -205,8 +271,4 @@ function trimit(e) {
|
|
|
205
271
|
}
|
|
206
272
|
a = a.trim();
|
|
207
273
|
return a.length === 0 ? null : a;
|
|
208
|
-
}
|
|
209
|
-
function readVIYACERT() {
|
|
210
|
-
var certs = null;
|
|
211
|
-
var certfile = process.env.VIYACERT;
|
|
212
274
|
}
|
package/package.json
CHANGED
package/src/iService.js
CHANGED
|
@@ -32,7 +32,7 @@ import readCerts from './readCerts';
|
|
|
32
32
|
|
|
33
33
|
let os = require('os');
|
|
34
34
|
|
|
35
|
-
function iService (userRouteTable, useDefault, asset, allAppEnv, serverMode, userCache) {
|
|
35
|
+
async function iService (userRouteTable, useDefault, asset, allAppEnv, serverMode, userCache) {
|
|
36
36
|
// process.env.APPHOST_ADDR = process.env.APPHOST;
|
|
37
37
|
const init = async () => {
|
|
38
38
|
|
|
@@ -211,14 +211,22 @@ function iService (userRouteTable, useDefault, asset, allAppEnv, serverMode, use
|
|
|
211
211
|
process.env.APPSERVER = `${hh}/${process.env.APPNAME}`;
|
|
212
212
|
process.env.HEALTH = 'true';
|
|
213
213
|
console.log('====================================================================================');
|
|
214
|
-
|
|
214
|
+
return `${hh}/${process.env.APPNAME}`
|
|
215
215
|
};
|
|
216
216
|
|
|
217
217
|
process.on('unhandledRejection', (err) => {
|
|
218
218
|
console.log(err);
|
|
219
219
|
process.exit(1);
|
|
220
220
|
});
|
|
221
|
-
|
|
221
|
+
try {
|
|
222
|
+
let r = await init();
|
|
223
|
+
return r;
|
|
224
|
+
}
|
|
225
|
+
catch(err){
|
|
226
|
+
|
|
227
|
+
console.log('Error starting server', err);
|
|
228
|
+
return false;
|
|
229
|
+
};
|
|
222
230
|
}
|
|
223
231
|
|
|
224
232
|
function getCertificates () {
|
package/src/index.js
CHANGED
|
@@ -26,7 +26,21 @@ import yargs from "yargs";
|
|
|
26
26
|
import { hideBin } from 'yargs/helpers';
|
|
27
27
|
let debug = require("debug")("startup");
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
exports.core = function () {
|
|
30
|
+
icore()
|
|
31
|
+
.then ((r) => {
|
|
32
|
+
console.log('icore returned', r);
|
|
33
|
+
return r;
|
|
34
|
+
})
|
|
35
|
+
.catch((err) => {
|
|
36
|
+
console.log('Error in icore', err);
|
|
37
|
+
return null;
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
exports.asyncCore = icore;
|
|
42
|
+
|
|
43
|
+
async function icore (
|
|
30
44
|
uTable,
|
|
31
45
|
useDefault,
|
|
32
46
|
serverMode,
|
|
@@ -56,10 +70,10 @@ module.exports = function core(
|
|
|
56
70
|
`
|
|
57
71
|
);
|
|
58
72
|
|
|
59
|
-
iapp(null, env, docker, uTable, useDefault, serverMode, customize,userCache);
|
|
73
|
+
return await iapp(null, env, docker, uTable, useDefault, serverMode, customize,userCache);
|
|
60
74
|
};
|
|
61
75
|
|
|
62
|
-
function iapp(
|
|
76
|
+
async function iapp(
|
|
63
77
|
appSrc,
|
|
64
78
|
rafEnv,
|
|
65
79
|
dockerFile,
|
|
@@ -75,18 +89,18 @@ function iapp(
|
|
|
75
89
|
}
|
|
76
90
|
if (appSrc != null) {
|
|
77
91
|
console.log("appSrc", `+${appSrc}+`);
|
|
78
|
-
createPayload(appSrc, (err, r) => {
|
|
92
|
+
createPayload(appSrc, async (err, r) => {
|
|
79
93
|
if (err) {
|
|
80
94
|
console.log(err);
|
|
81
95
|
console.log("createPayload failed");
|
|
82
96
|
process.exit(1);
|
|
83
97
|
} else {
|
|
84
|
-
iService(uTable, useDefault, asset, r, serverMode, customize, userCache);
|
|
98
|
+
return await iService(uTable, useDefault, asset, r, serverMode, customize, userCache);
|
|
85
99
|
}
|
|
86
100
|
});
|
|
87
101
|
} else {
|
|
88
102
|
let appEnv = getAllEnv({});
|
|
89
|
-
iService(uTable, useDefault, asset, appEnv, serverMode, customize, userCache);
|
|
103
|
+
return await iService(uTable, useDefault, asset, appEnv, serverMode, customize, userCache);
|
|
90
104
|
}
|
|
91
105
|
}
|
|
92
106
|
|
|
@@ -253,8 +267,3 @@ function trimit(e) {
|
|
|
253
267
|
return a.length === 0 ? null : a;
|
|
254
268
|
}
|
|
255
269
|
|
|
256
|
-
function readVIYACERT(){
|
|
257
|
-
let certs = null;
|
|
258
|
-
let certfile = process.env.VIYACERT;
|
|
259
|
-
|
|
260
|
-
}
|