@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 CHANGED
@@ -15,4 +15,5 @@ HTTPS=true
15
15
 
16
16
  VIYACERT=c:\Users\kumar\viyaCert\xf1
17
17
  NODE_TLS_REJECT_UNAUTHORIZED=0
18
+ AUTOSTART=TRUE
18
19
 
package/autoStart.js ADDED
@@ -0,0 +1,6 @@
1
+ import open from 'open';
2
+ async function autoStart(url) {
3
+ await open(url, {wait:true});
4
+ console.error(`[Note]URL: ${url} closed by user`);
5
+ }
6
+ export default autoStart;
package/cli.js CHANGED
@@ -4,7 +4,25 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
- let core = require('./lib/index.js');
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
- core(null, true, 'app', null, userCache);
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(userRouteTable, useDefault, asset, allAppEnv, serverMode, userCache) {
51
- // process.env.APPHOST_ADDR = process.env.APPHOST;
52
- var init = /*#__PURE__*/function () {
53
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
54
- var defaultMaxBytes, maxBytes, isSameSite, isSecure, https, _process$env$SAMESITE, _process$env$SAMESITE2, s1, s2, sConfig, hapiServer, nodeCacheOptions, storeCache, visionOptions, options, allRoutes, hh, msg;
55
- return _regenerator().w(function (_context) {
56
- while (1) switch (_context.n) {
57
- case 0:
58
- if (process.env.APPHOST === '*') {
59
- process.env.APPHOST = os.hostname();
60
- }
61
- defaultMaxBytes = 10485760;
62
- if (isNaN(process.env.PAYLOADMAXBYTES)) {
63
- maxBytes = defaultMaxBytes;
64
- } else {
65
- maxBytes = Number(process.env.PAYLOADMAXBYTES);
66
- }
67
- isSameSite = 'Lax';
68
- isSecure = false;
69
- https = process.env.HTTPS || 'TRUE';
70
- https = https.toUpperCase();
71
- if (process.env.SAMESITE != null) {
72
- _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];
73
- isSameSite = s1;
74
- isSecure = s2 === 'secure' ? true : false;
75
- if (https !== 'TRUE') {
76
- isSecure = false;
77
- }
78
- }
79
- sConfig = {
80
- port: process.env.APPPORT,
81
- host: process.env.APPHOST,
82
- state: {
83
- isSameSite: isSameSite,
84
- isSecure: isSecure
85
- },
86
- routes: {
87
- payload: {
88
- maxBytes: maxBytes
89
- },
90
- cors: {
91
- origin: ['*'],
92
- credentials: true,
93
- "headers": ["Accept", "Authorization", "Content-Type", "If-None-Match", "Accept-language"]
94
- /*
95
- 'Access-Control-Allow-Methods': ['GET', 'POST', 'OPTIONS'],
96
- additionalHeaders : ['multipart/form-data', 'content-disposition'],
97
- additionalExposedHeaders : ['location'],
98
- */
99
- }
100
- }
101
- };
102
- if (process.env.HAPIDEBUG === 'YES') {
103
- sConfig.debug = {
104
- request: '*'
105
- };
106
- }
107
- debug(JSON.stringify(sConfig, null, 4));
108
- if (https === 'TRUE') {
109
- sConfig.tls = getCertificates();
110
- debug('Setup of SSL certificates completed');
111
- } else {
112
- debug('Running with no SSL certificates');
113
- }
114
- if (asset !== null) {
115
- sConfig.routes.files = {
116
- relativeTo: asset
117
- };
118
- }
119
- debug2("Application information: \n\t\tAPPLOC : ".concat(process.env.APPLOC, "\n\t\tAPPENTRY: ").concat(process.env.APPENTRY, "\n"));
120
- hapiServer = Hapi.server(sConfig);
121
- /*
122
- const cache = hapiServer.cache({ segment: 'sid', expiresIn: 3 * 24 * 60 * 60 * 1000 });
123
- hapiServer.app.cache = cache;
124
- */
125
- nodeCacheOptions = {
126
- stdTTL: 24 * 60 * 60 * 1000,
127
- checkPeriod: 3600,
128
- errorOnMissing: true,
129
- useClones: false,
130
- deleteOnExpire: true
131
- };
132
- storeCache = new NodeCache(nodeCacheOptions);
133
- hapiServer.app.cache = storeCache;
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
- // common plugins
136
- visionOptions = {
137
- engines: {
138
- html: require('handlebars')
139
- },
140
- relativeTo: __dirname,
141
- path: '.'
142
- };
143
- _context.n = 1;
144
- return hapiServer.register(Vision);
145
- case 1:
146
- hapiServer.views(visionOptions);
147
- _context.n = 2;
148
- return hapiServer.register(inert);
149
- case 2:
150
- if (!(https === 'TRUE')) {
151
- _context.n = 3;
152
- break;
153
- }
154
- _context.n = 3;
155
- return hapiServer.register({
156
- plugin: require('hapi-require-https'),
157
- options: {}
158
- });
159
- case 3:
160
- _context.n = 4;
161
- return hapiServer.register(H202);
162
- case 4:
163
- // setup authentication related plugins
164
- options = {
165
- serverMode: serverMode,
166
- authFlow: process.env.AUTHFLOW,
167
- host: process.env.VIYA_SERVER,
168
- isSameSite: isSameSite,
169
- isSecure: isSecure,
170
- ns: allAppEnv.LOGONPAYLOAD != null ? allAppEnv.LOGONPAYLOAD.ns : null,
171
- nsHost: allAppEnv.LOGONPAYLOAD != null ? allAppEnv.LOGONPAYLOAD.nsHost : null,
172
- redirect: process.env.REDIRECT,
173
- clientId: process.env.CLIENTID,
174
- clientSecret: process.env.CLIENTSECRET,
175
- redirectTo: "/".concat(process.env.APPNAME, "/logon"),
176
- allAppEnv: allAppEnv,
177
- useHapiCookie: true,
178
- appName: process.env.APPNAME,
179
- appHost: process.env.APPHOST,
180
- appPort: process.env.APPPORT,
181
- userRouteTable: userRouteTable,
182
- useDefault: useDefault,
183
- /* not used - left here for potential reuse */
184
- userCache: userCache || {},
185
- https: https,
186
- authDefault: false,
187
- /* set later in setDefaultRoutes */
188
- authLogon: false /* set later in setDefaultRoutes */
189
- };
190
- debug2('Options', options);
191
- if (!(process.env.AUTHFLOW != null)) {
192
- _context.n = 6;
193
- break;
194
- }
195
- _context.n = 5;
196
- return (0, _setupAuth["default"])(hapiServer, options);
197
- case 5:
198
- if (process.env.PREAUTH === 'YES') {
199
- console.log('Preauth enabled');
200
- hapiServer.ext('onPreAuth', function (request, h) {
201
- debugger;
202
- if (!request.auth.isAuthenticated && !request.path.startsWith("/login")) {
203
- var redirectTo = "".concat(request.path, "?").concat(new URLSearchParams(request.query).toString());
204
- console.log('Redirect to login', {
205
- redirectTo: redirectTo
206
- });
207
- debugger;
208
- return h.redirect("/login").takeover();
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
- return h["continue"];
211
- });
212
- }
213
- case 6:
214
- //
215
- // Start server
216
- //
217
- // eslint-disable-next-line no-unused-vars
218
- allRoutes = hapiServer.table();
219
- _context.n = 7;
220
- return hapiServer.start();
221
- case 7:
222
- hh = hapiServer.info.uri;
223
- hh = hh.replace(/0.0.0.0/, 'localhost');
224
- console.log('====================================================================================');
225
- console.log('Server Start Time: ', Date());
226
- 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");
227
- console.log('\x1b[1m%s\x1b[0m', msg);
228
- console.log('NOTE: If running in container use the exported port');
229
- process.env.APPSERVER = "".concat(hh, "/").concat(process.env.APPNAME);
230
- process.env.HEALTH = 'true';
231
- console.log('====================================================================================');
232
- case 8:
233
- return _context.a(2);
234
- }
235
- }, _callee);
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
- module.exports = function core(uTable, useDefault, serverMode, customize, userCache) {
32
- var argv = (0, _yargs["default"])((0, _helpers.hideBin)(process.argv)).argv;
33
- var env = argv.env == null ? null : argv.env;
34
- var appenv = argv.appenv == null ? null : argv.appenv;
35
- var docker = argv.docker == null ? null : argv.docker;
36
- //process.env.SERVERMODE = serverMode !== null ? "api" : "app";
37
-
38
- if (useDefault == null) {
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
- function iapp(appSrc, rafEnv, dockerFile, uTable, useDefault, serverMode, customize, userCache) {
47
- var asset = setup(rafEnv, dockerFile);
48
- if (appSrc == null) {
49
- appSrc = process.env.APPENV == null ? null : process.env.APPENV;
50
- }
51
- if (appSrc != null) {
52
- console.log("appSrc", "+".concat(appSrc, "+"));
53
- createPayload(appSrc, function (err, r) {
54
- if (err) {
55
- console.log(err);
56
- console.log("createPayload failed");
57
- process.exit(1);
58
- } else {
59
- (0, _iService["default"])(uTable, useDefault, asset, r, serverMode, customize, userCache);
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
- } else {
63
- var appEnv = getAllEnv({});
64
- (0, _iService["default"])(uTable, useDefault, asset, appEnv, serverMode, customize, userCache);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sassoftware/viya-serverjs",
3
- "version": "0.6.2",
3
+ "version": "0.6.3-0",
4
4
  "description": "Easy to use app server for SAS Viya applications",
5
5
  "author": "Deva Kumaraswamy <deva.kumar@sas.com>",
6
6
  "license": "Apache-2.0",
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
- init();
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
- module.exports = function core(
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
- }