@sassoftware/viya-serverjs 0.5.0 → 0.5.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/.env +6 -4
- package/.env.server +28 -17
- package/Dockerfile +1 -1
- package/lib/handlers/codeAuth.js +9 -11
- package/lib/iService.js +38 -22
- package/lib/plugins/setContext.js +1 -0
- package/lib/plugins/setDefaultRoutes.js +48 -32
- package/lib/plugins/setupUserRoutes.js +4 -11
- package/package.json +4 -4
- package/public/auth.html +24 -0
- package/public/help.html +1 -1
- package/server.js +10 -6
- package/src/handlers/codeAuth.js +10 -10
- package/src/iService.js +144 -121
- package/src/plugins/setContext.js +2 -1
- package/src/plugins/setDefaultRoutes.js +11 -7
- package/src/plugins/setupUserRoutes.js +2 -6
- package/testca.js +10 -0
- package/public/indexProxy.html +0 -351
- package/public/simplesubmit.html +0 -233
package/.env
CHANGED
|
@@ -4,16 +4,17 @@ APPLOC=./public
|
|
|
4
4
|
# VIYA_SERVER=your viya server
|
|
5
5
|
|
|
6
6
|
APPPORT=8080
|
|
7
|
-
APPNAME=
|
|
7
|
+
APPNAME=mcpserver
|
|
8
8
|
AUTHFLOW=code
|
|
9
|
-
CLIENTID=
|
|
9
|
+
CLIENTID=mcpserver
|
|
10
10
|
CLIENTSECRET=jellico
|
|
11
|
+
USELOGON=TRUE
|
|
12
|
+
USETOKEN=TRUE
|
|
11
13
|
|
|
12
|
-
REDIRECT=
|
|
14
|
+
//REDIRECT=mcp
|
|
13
15
|
# APPDIR=./appDir
|
|
14
16
|
HTTPS=true
|
|
15
17
|
|
|
16
|
-
|
|
17
18
|
# Most modern browsers do not accept self-signed certs from localhost
|
|
18
19
|
# Options:
|
|
19
20
|
|
|
@@ -26,6 +27,7 @@ HTTPS=true
|
|
|
26
27
|
// either use the proper ssl/tsl certs or use the "proxy" method
|
|
27
28
|
// to avoid CORS issues with self-signed certs
|
|
28
29
|
// so run all apps thru the proxy and call Viya from there
|
|
30
|
+
|
|
29
31
|
APPENV_PROXY=false
|
|
30
32
|
|
|
31
33
|
|
package/.env.server
CHANGED
|
@@ -1,32 +1,43 @@
|
|
|
1
1
|
APPHOST=localhost
|
|
2
|
-
APPENTRY=index.html
|
|
2
|
+
# APPENTRY=index.html
|
|
3
3
|
APPLOC=./public
|
|
4
|
-
# viya
|
|
5
|
-
# VIYA_SERVER=
|
|
6
|
-
APPENV_PROXYSERVER=https://localhost:8080/viyaapp/proxy
|
|
4
|
+
# VIYA_SERVER=your viya server
|
|
7
5
|
|
|
8
6
|
APPPORT=8080
|
|
9
|
-
APPNAME=
|
|
10
|
-
AUTHFLOW=
|
|
11
|
-
CLIENTID=
|
|
7
|
+
APPNAME=mcpserver
|
|
8
|
+
AUTHFLOW=code
|
|
9
|
+
CLIENTID=mcpserver
|
|
12
10
|
CLIENTSECRET=jellico
|
|
13
|
-
|
|
11
|
+
USELOGON=TRUE
|
|
12
|
+
USETOKEN=TRUE
|
|
13
|
+
|
|
14
|
+
REDIRECT=mcp
|
|
14
15
|
# APPDIR=./appDir
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
HTTPS=true
|
|
17
|
+
|
|
18
|
+
# Most modern browsers do not accept self-signed certs from localhost
|
|
19
|
+
# Options:
|
|
20
|
+
|
|
21
|
+
# 1. provide signed certificates for localhost
|
|
22
|
+
# 2. Use libraries like mkcert to create temporary trusted certs for localhost
|
|
23
|
+
# 3. Use the app server as a proxy to the Viya server to avoid CORS issues.
|
|
24
|
+
# This requires that the app redirect all Viya API calls to the app server proxy endpoint
|
|
25
|
+
# Users of restaf can simply set the APPENV_PROXY env to TRUE to enable this behavior
|
|
26
|
+
# 4. set USETOKEN to TRUE and use the token in the APPENV object to make the calls
|
|
27
|
+
// either use the proper ssl/tsl certs or use the "proxy" method
|
|
28
|
+
// to avoid CORS issues with self-signed certs
|
|
29
|
+
// so run all apps thru the proxy and call Viya from there
|
|
30
|
+
APPENV_PROXY=false
|
|
17
31
|
|
|
18
32
|
|
|
19
|
-
|
|
20
|
-
#
|
|
21
|
-
|
|
33
|
+
# APPENV_PROXYSERVER=true
|
|
34
|
+
# USETOKEN=true
|
|
35
|
+
SHOWENV=true
|
|
36
|
+
|
|
22
37
|
APPENV_XYZ=AA
|
|
23
38
|
APPENV_BAD=
|
|
24
39
|
|
|
25
40
|
|
|
26
41
|
|
|
27
|
-
# NAMESPACE=viya
|
|
28
|
-
# TLS_CERT=./certs/tls.crt
|
|
29
|
-
# TLS_KEY=./certs/tls.key
|
|
30
|
-
|
|
31
42
|
|
|
32
43
|
|
package/Dockerfile
CHANGED
|
@@ -30,7 +30,7 @@ ENV CLIENTSECRET=
|
|
|
30
30
|
|
|
31
31
|
# specify ssl/tls cert and key in a folder
|
|
32
32
|
# example below
|
|
33
|
-
ENV SSLCERT=c:/Users/kumar/.tls
|
|
33
|
+
# ENV SSLCERT=c:/Users/kumar/.tls
|
|
34
34
|
#sample setup for creating a temporary cert and key
|
|
35
35
|
ENV TLS_CREATE="C:US,ST:NC,L:Cary,O:SAS Institute,OU:STO,CN:localhost"
|
|
36
36
|
|
package/lib/handlers/codeAuth.js
CHANGED
|
@@ -20,7 +20,7 @@ function codeAuth(_x, _x2, _x3) {
|
|
|
20
20
|
}
|
|
21
21
|
function _codeAuth() {
|
|
22
22
|
_codeAuth = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(req, h, options) {
|
|
23
|
-
var indexHTML;
|
|
23
|
+
var indexHTML, redirectPath;
|
|
24
24
|
return _regenerator().w(function (_context) {
|
|
25
25
|
while (1) switch (_context.n) {
|
|
26
26
|
case 0:
|
|
@@ -29,22 +29,20 @@ function _codeAuth() {
|
|
|
29
29
|
return (0, _setCookies["default"])(req, h, options);
|
|
30
30
|
case 1:
|
|
31
31
|
debug(options);
|
|
32
|
+
// add support for REDIRECT env variable
|
|
32
33
|
indexHTML = process.env.APPENTRY == null ? 'index.html' : process.env.APPENTRY;
|
|
34
|
+
redirectPath = null;
|
|
33
35
|
if (process.env.REDIRECT != null) {
|
|
34
|
-
|
|
35
|
-
indexHTML = process.env.REDIRECT;
|
|
36
|
+
redirectPath = process.env.REDIRECT != null && process.env.REDIRECT.startsWith('/') ? "/".concat(process.env.APPNAME).concat(process.env.REDIRECT) : "/".concat(process.env.REDIRECT);
|
|
36
37
|
}
|
|
37
|
-
debug(
|
|
38
|
-
|
|
38
|
+
debug(indexHTML);
|
|
39
|
+
debug(redirectPath);
|
|
40
|
+
if (!(redirectPath !== null)) {
|
|
39
41
|
_context.n = 2;
|
|
40
42
|
break;
|
|
41
43
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
indexHTML = "/".concat(process.env.APPNAME).concat(indexHTML);
|
|
45
|
-
}
|
|
46
|
-
console.log("Redirecting to ".concat(indexHTML));
|
|
47
|
-
return _context.a(2, h.redirect(indexHTML));
|
|
44
|
+
debug('redirecting to', redirectPath);
|
|
45
|
+
return _context.a(2, h.redirect(redirectPath));
|
|
48
46
|
case 2:
|
|
49
47
|
console.log("Visiting ".concat(indexHTML));
|
|
50
48
|
return _context.a(2, h.file(indexHTML));
|
package/lib/iService.js
CHANGED
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports["default"] = void 0;
|
|
8
|
-
var _file = require("@hapi/inert/lib/file");
|
|
9
8
|
var _setupAuth = _interopRequireDefault(require("./plugins/setupAuth"));
|
|
10
9
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
11
10
|
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 }; })(); }
|
|
@@ -181,11 +180,13 @@ function iService(userRouteTable, useDefault, asset, allAppEnv, serverMode, user
|
|
|
181
180
|
},
|
|
182
181
|
});
|
|
183
182
|
*/
|
|
183
|
+
//
|
|
184
184
|
// setup authentication related plugins
|
|
185
185
|
options = {
|
|
186
186
|
serverMode: serverMode,
|
|
187
187
|
authFlow: process.env.AUTHFLOW,
|
|
188
188
|
host: process.env.VIYA_SERVER,
|
|
189
|
+
useLogon: process.env.USELOGON != null && process.env.USELOGON.toUpperCase() === 'FALSE' ? false : true,
|
|
189
190
|
isSameSite: isSameSite,
|
|
190
191
|
isSecure: isSecure,
|
|
191
192
|
ns: allAppEnv.LOGONPAYLOAD != null ? allAppEnv.LOGONPAYLOAD.ns : null,
|
|
@@ -317,6 +318,7 @@ function _getCertificates() {
|
|
|
317
318
|
case 0:
|
|
318
319
|
options = null;
|
|
319
320
|
tlsdir = process.env.SSLCERT;
|
|
321
|
+
console.log('Reading SSL certificates from ', tlsdir);
|
|
320
322
|
if (!(tlsdir != null && tlsdir.trim().length > 0)) {
|
|
321
323
|
_context2.n = 1;
|
|
322
324
|
break;
|
|
@@ -406,28 +408,42 @@ function _getTls() {
|
|
|
406
408
|
shortName: 'OU',
|
|
407
409
|
value: d.OU
|
|
408
410
|
}];
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
411
|
+
/*
|
|
412
|
+
options.extensions.altNames = [
|
|
413
|
+
// { type: 6, value: `http://${process.env.APPHOST}:${process.env.APPPORT}/${process.env.APPNAME}` },
|
|
414
|
+
{ type: 6, value: `https://${process.env.APPHOST}:${process.env.APPPORT}/${process.env.APPNAME}` },
|
|
415
|
+
{ type: 6, value: `https://${process.env.APPHOST}:${process.env.APPPORT}/${process.env.APPNAME}/api` },
|
|
416
|
+
{ type: 6, value: `https://${process.env.APPHOST}:${process.env.APPPORT}/${process.env.APPNAME}/logon` },
|
|
417
|
+
{ type: 6, value: `https://${process.env.APPHOST}/${process.env.APPNAME}` },
|
|
418
|
+
{ type: 6, value: `https://${process.env.APPHOST}/${process.env.APPNAME}/api` },
|
|
419
|
+
{ type: 6, value: `https://${process.env.APPHOST}/${process.env.APPNAME}/logon` },
|
|
420
|
+
];
|
|
421
|
+
|
|
422
|
+
options.extensions.altNames = [
|
|
423
|
+
{ type: 2, value: 'localhost' }, // DNS
|
|
424
|
+
{ type: 7, ip: '127.0.0.1' }, // IPv4
|
|
425
|
+
{ type: 7, ip: '::1' } // IPv6
|
|
426
|
+
];
|
|
427
|
+
*/
|
|
428
|
+
options.extensions = [{
|
|
429
|
+
name: 'subjectAltName',
|
|
430
|
+
altNames: [{
|
|
431
|
+
type: 2,
|
|
432
|
+
value: 'localhost'
|
|
433
|
+
},
|
|
434
|
+
// DNS
|
|
435
|
+
{
|
|
436
|
+
type: 7,
|
|
437
|
+
ip: '127.0.0.1'
|
|
438
|
+
},
|
|
439
|
+
// IPv4
|
|
440
|
+
{
|
|
441
|
+
type: 7,
|
|
442
|
+
ip: '::1'
|
|
443
|
+
} // IPv6
|
|
444
|
+
]
|
|
429
445
|
}];
|
|
430
|
-
|
|
446
|
+
console.log('tls options ', JSON.stringify(options, null, 4));
|
|
431
447
|
pems = selfsigned.generate(attr, options);
|
|
432
448
|
tls = {
|
|
433
449
|
cert: pems.cert,
|
|
@@ -56,7 +56,7 @@ module.exports = function setDefaultRoutes(server, options) {
|
|
|
56
56
|
method: ["GET"],
|
|
57
57
|
path: "".concat(appName, "/logon"),
|
|
58
58
|
options: {
|
|
59
|
-
auth: options.authFlow === "server" ? {
|
|
59
|
+
auth: /*authLogon*/options.authFlow === "server" ? {
|
|
60
60
|
mode: "try",
|
|
61
61
|
strategy: "sas"
|
|
62
62
|
} : null,
|
|
@@ -72,7 +72,7 @@ module.exports = function setDefaultRoutes(server, options) {
|
|
|
72
72
|
return _regenerator().w(function (_context) {
|
|
73
73
|
while (1) switch (_context.n) {
|
|
74
74
|
case 0:
|
|
75
|
-
|
|
75
|
+
console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>in logon');
|
|
76
76
|
_context.n = 1;
|
|
77
77
|
return (0, _handlers.logon)(req, h);
|
|
78
78
|
case 1:
|
|
@@ -90,20 +90,15 @@ module.exports = function setDefaultRoutes(server, options) {
|
|
|
90
90
|
method: ["GET"],
|
|
91
91
|
path: "".concat(appName),
|
|
92
92
|
options: {
|
|
93
|
-
auth: process.env.USELOGON === '
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
}, {
|
|
97
|
-
method: ["GET"],
|
|
98
|
-
path: "".concat(appName, "/api"),
|
|
99
|
-
options: {
|
|
100
|
-
auth: authDefault,
|
|
93
|
+
//auth: (process.env.USELOGON.toUpperCase() === 'TRUE') ? null : options.serverMode === "app" ? authLogon : authDefault,
|
|
94
|
+
auth: null,
|
|
101
95
|
handler: function () {
|
|
102
96
|
var _handler2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(req, h) {
|
|
103
97
|
return _regenerator().w(function (_context2) {
|
|
104
98
|
while (1) switch (_context2.n) {
|
|
105
99
|
case 0:
|
|
106
|
-
|
|
100
|
+
console.log(">>>>>>>>>>>>>>>>>>>>>>>in ".concat(appName));
|
|
101
|
+
return _context2.a(2, getAppb(req, h));
|
|
107
102
|
}
|
|
108
103
|
}, _callee2);
|
|
109
104
|
}));
|
|
@@ -113,6 +108,26 @@ module.exports = function setDefaultRoutes(server, options) {
|
|
|
113
108
|
return handler;
|
|
114
109
|
}()
|
|
115
110
|
}
|
|
111
|
+
}, {
|
|
112
|
+
method: ["GET"],
|
|
113
|
+
path: "".concat(appName, "/api"),
|
|
114
|
+
options: {
|
|
115
|
+
auth: authDefault,
|
|
116
|
+
handler: function () {
|
|
117
|
+
var _handler3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(req, h) {
|
|
118
|
+
return _regenerator().w(function (_context3) {
|
|
119
|
+
while (1) switch (_context3.n) {
|
|
120
|
+
case 0:
|
|
121
|
+
return _context3.a(2, h.redirect("".concat(appName, "/documentation")));
|
|
122
|
+
}
|
|
123
|
+
}, _callee3);
|
|
124
|
+
}));
|
|
125
|
+
function handler(_x5, _x6) {
|
|
126
|
+
return _handler3.apply(this, arguments);
|
|
127
|
+
}
|
|
128
|
+
return handler;
|
|
129
|
+
}()
|
|
130
|
+
}
|
|
116
131
|
}, {
|
|
117
132
|
method: ["GET"],
|
|
118
133
|
path: "/develop",
|
|
@@ -148,10 +163,10 @@ module.exports = function setDefaultRoutes(server, options) {
|
|
|
148
163
|
options: {
|
|
149
164
|
auth: /*authDefault*/false,
|
|
150
165
|
handler: function () {
|
|
151
|
-
var
|
|
166
|
+
var _handler4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(req, h) {
|
|
152
167
|
var allAppEnv, uappenv, s;
|
|
153
|
-
return _regenerator().w(function (
|
|
154
|
-
while (1) switch (
|
|
168
|
+
return _regenerator().w(function (_context4) {
|
|
169
|
+
while (1) switch (_context4.n) {
|
|
155
170
|
case 0:
|
|
156
171
|
allAppEnv = options.allAppEnv;
|
|
157
172
|
if (options.userInfo != null) {
|
|
@@ -166,12 +181,12 @@ module.exports = function setDefaultRoutes(server, options) {
|
|
|
166
181
|
console.log(s);
|
|
167
182
|
}
|
|
168
183
|
debug(s);
|
|
169
|
-
return
|
|
184
|
+
return _context4.a(2, s);
|
|
170
185
|
}
|
|
171
|
-
},
|
|
186
|
+
}, _callee4);
|
|
172
187
|
}));
|
|
173
|
-
function handler(
|
|
174
|
-
return
|
|
188
|
+
function handler(_x7, _x8) {
|
|
189
|
+
return _handler4.apply(this, arguments);
|
|
175
190
|
}
|
|
176
191
|
return handler;
|
|
177
192
|
}()
|
|
@@ -182,10 +197,10 @@ module.exports = function setDefaultRoutes(server, options) {
|
|
|
182
197
|
options: {
|
|
183
198
|
auth: /*authDefault*/false,
|
|
184
199
|
handler: function () {
|
|
185
|
-
var
|
|
200
|
+
var _handler5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(req, h) {
|
|
186
201
|
var allAppEnv, uappenv, s;
|
|
187
|
-
return _regenerator().w(function (
|
|
188
|
-
while (1) switch (
|
|
202
|
+
return _regenerator().w(function (_context5) {
|
|
203
|
+
while (1) switch (_context5.n) {
|
|
189
204
|
case 0:
|
|
190
205
|
allAppEnv = options.allAppEnv;
|
|
191
206
|
if (options.userInfo != null) {
|
|
@@ -200,12 +215,12 @@ module.exports = function setDefaultRoutes(server, options) {
|
|
|
200
215
|
debug(options.allAppEnv);
|
|
201
216
|
}
|
|
202
217
|
debug(s);
|
|
203
|
-
return
|
|
218
|
+
return _context5.a(2, s);
|
|
204
219
|
}
|
|
205
|
-
},
|
|
220
|
+
}, _callee5);
|
|
206
221
|
}));
|
|
207
|
-
function handler(
|
|
208
|
-
return
|
|
222
|
+
function handler(_x9, _x0) {
|
|
223
|
+
return _handler5.apply(this, arguments);
|
|
209
224
|
}
|
|
210
225
|
return handler;
|
|
211
226
|
}()
|
|
@@ -228,17 +243,17 @@ module.exports = function setDefaultRoutes(server, options) {
|
|
|
228
243
|
options: {
|
|
229
244
|
auth: authDefault,
|
|
230
245
|
handler: function () {
|
|
231
|
-
var
|
|
232
|
-
return _regenerator().w(function (
|
|
233
|
-
while (1) switch (
|
|
246
|
+
var _handler6 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(req, h) {
|
|
247
|
+
return _regenerator().w(function (_context6) {
|
|
248
|
+
while (1) switch (_context6.n) {
|
|
234
249
|
case 0:
|
|
235
250
|
console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>in param');
|
|
236
|
-
return
|
|
251
|
+
return _context6.a(2, (0, _handlers.getApp2)(req, h));
|
|
237
252
|
}
|
|
238
|
-
},
|
|
253
|
+
}, _callee6);
|
|
239
254
|
}));
|
|
240
|
-
function handler(
|
|
241
|
-
return
|
|
255
|
+
function handler(_x1, _x10) {
|
|
256
|
+
return _handler6.apply(this, arguments);
|
|
242
257
|
}
|
|
243
258
|
return handler;
|
|
244
259
|
}()
|
|
@@ -279,6 +294,7 @@ module.exports = function setDefaultRoutes(server, options) {
|
|
|
279
294
|
method: _setContext["default"],
|
|
280
295
|
assign: 'context'
|
|
281
296
|
}];
|
|
297
|
+
console.log, 'Setting pre for route', r.path, r.options.pre;
|
|
282
298
|
});
|
|
283
299
|
var routeTables = uTable !== null ? defaultTable.concat(uTable) : defaultTable;
|
|
284
300
|
server.route(routeTables);
|
|
@@ -6,12 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports["default"] = void 0;
|
|
7
7
|
var _setContext = _interopRequireDefault(require("./setContext"));
|
|
8
8
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
9
|
-
|
|
10
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
11
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
12
|
-
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
13
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
14
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /*
|
|
9
|
+
/*
|
|
15
10
|
* ------------------------------------------------------------------------------------
|
|
16
11
|
* Copyright (c) SAS Institute Inc.
|
|
17
12
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -28,6 +23,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
28
23
|
* ---------------------------------------------------------------------------------------
|
|
29
24
|
*
|
|
30
25
|
*/
|
|
26
|
+
|
|
31
27
|
function setupUserRoutes(u, options) {
|
|
32
28
|
if (u == null) {
|
|
33
29
|
return [];
|
|
@@ -35,11 +31,7 @@ function setupUserRoutes(u, options) {
|
|
|
35
31
|
var ux = typeof u === 'function' ? u() : u;
|
|
36
32
|
var routes = ux.map(function (rx) {
|
|
37
33
|
//let rx = {...r};
|
|
38
|
-
|
|
39
|
-
if (rx.config != null) {
|
|
40
|
-
rx.options = _objectSpread({}, rx.config);
|
|
41
|
-
delete rx.config;
|
|
42
|
-
}
|
|
34
|
+
|
|
43
35
|
if (rx.options.pre == null) {
|
|
44
36
|
rx.options.pre = [{
|
|
45
37
|
method: _setContext["default"],
|
|
@@ -57,6 +49,7 @@ function setupUserRoutes(u, options) {
|
|
|
57
49
|
} else if (rx.options.auth === 'logon') {
|
|
58
50
|
rx.options.auth = options.authLogon;
|
|
59
51
|
}
|
|
52
|
+
console.log('route auth', rx.options.auth);
|
|
60
53
|
return rx;
|
|
61
54
|
});
|
|
62
55
|
return routes;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sassoftware/viya-serverjs",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
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",
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
"scripts": {
|
|
31
31
|
"build": "rimraf lib && babel src --out-dir lib",
|
|
32
32
|
"test": "node cli --env=./.env --docker=./Dockerfile",
|
|
33
|
-
"
|
|
34
|
-
"
|
|
33
|
+
"testbg": "cross-env APPENTRY=auth.html node cli --env=./.env --docker=./Dockerfile",
|
|
34
|
+
"testmcp": "node server.js --env=./.env --docker=./Dockerfile",
|
|
35
35
|
"debug": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk server.js --env=./.env.server --docker=./Dockerfile",
|
|
36
36
|
"proxy": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli --env=./.env.proxy --docker=./Dockerfile",
|
|
37
|
-
"pub": "npm publish --tag
|
|
37
|
+
"pub": "npm publish --tag alpha --access public",
|
|
38
38
|
"lint": "npx eslint --fix src/*.js"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
package/public/auth.html
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
<!DOCTYPE html>
|
|
3
|
+
<html>
|
|
4
|
+
<body>
|
|
5
|
+
<script>
|
|
6
|
+
(function () {
|
|
7
|
+
try {
|
|
8
|
+
// Notify parent window that auth succeeded.
|
|
9
|
+
if (window.opener && !window.opener.closed) {
|
|
10
|
+
window.opener.postMessage(
|
|
11
|
+
{ type: 'oauth:success', state: 200 },
|
|
12
|
+
'*'
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
} catch (e) {
|
|
16
|
+
// ignore
|
|
17
|
+
}
|
|
18
|
+
// Attempt to close the popup.
|
|
19
|
+
window.close();
|
|
20
|
+
})();
|
|
21
|
+
</script>
|
|
22
|
+
<p>Server is active. You can close this window.</p>
|
|
23
|
+
</body>
|
|
24
|
+
</html>`;
|
package/public/help.html
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<h1>
|
|
1
|
+
<h1> MCP Server is ready</h1>
|
package/server.js
CHANGED
|
@@ -9,6 +9,7 @@ core(getCustomHandler, true, 'app', null);
|
|
|
9
9
|
function getCustomHandler() {
|
|
10
10
|
let appName = `/${process.env.APPNAME}`; /* does not have to be this - your choice */
|
|
11
11
|
debugger;
|
|
12
|
+
console.log('getCustomHandler called for appName', appName);
|
|
12
13
|
let routes = [
|
|
13
14
|
{
|
|
14
15
|
method: ["GET"],
|
|
@@ -22,24 +23,27 @@ function getCustomHandler() {
|
|
|
22
23
|
let hf = 'help.html';
|
|
23
24
|
return h.file(hf);
|
|
24
25
|
},
|
|
25
|
-
auth:
|
|
26
|
+
auth: true,
|
|
26
27
|
description: "Help",
|
|
27
28
|
notes: "Help",
|
|
28
29
|
tags: ["app"],
|
|
29
30
|
},
|
|
30
31
|
},
|
|
31
32
|
{
|
|
32
|
-
method: ["GET"],
|
|
33
|
-
path:
|
|
33
|
+
method: ["POST", "GET"],
|
|
34
|
+
path: `/mcp`,
|
|
34
35
|
options: {
|
|
35
36
|
files: {
|
|
36
37
|
relativeTo: "./public",
|
|
37
38
|
},
|
|
38
39
|
handler: async (req, h) => {
|
|
39
|
-
console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>in
|
|
40
|
-
|
|
40
|
+
console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>in imcp');
|
|
41
|
+
console.log('credentials', req.auth.credentials);
|
|
42
|
+
debugger;
|
|
43
|
+
console.log('pre', req.pre.context);
|
|
44
|
+
return h.file('help.html');
|
|
41
45
|
},
|
|
42
|
-
|
|
46
|
+
auth: 'logon',
|
|
43
47
|
description: "Create new application",
|
|
44
48
|
notes: "Index file created from env data",
|
|
45
49
|
tags: ["app"],
|
package/src/handlers/codeAuth.js
CHANGED
|
@@ -10,19 +10,19 @@ async function codeAuth (req, h, options) {
|
|
|
10
10
|
debug('in codeauth');
|
|
11
11
|
await setCookies(req, h, options);
|
|
12
12
|
debug(options);
|
|
13
|
+
// add support for REDIRECT env variable
|
|
13
14
|
let indexHTML = process.env.APPENTRY == null ? 'index.html' : process.env.APPENTRY;
|
|
15
|
+
let redirectPath = null;
|
|
14
16
|
if (process.env.REDIRECT != null) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
redirectPath = (process.env.REDIRECT != null && process.env.REDIRECT.startsWith('/')
|
|
18
|
+
? `/${process.env.APPNAME}${process.env.REDIRECT}`
|
|
19
|
+
: `/${process.env.REDIRECT}`);
|
|
17
20
|
}
|
|
18
|
-
debug(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
console.log(`Redirecting to ${indexHTML}`);
|
|
25
|
-
return h.redirect(indexHTML);
|
|
21
|
+
debug(indexHTML);
|
|
22
|
+
debug(redirectPath);
|
|
23
|
+
if (redirectPath !== null) {
|
|
24
|
+
debug('redirecting to', redirectPath);
|
|
25
|
+
return h.redirect(redirectPath);
|
|
26
26
|
} else {
|
|
27
27
|
console.log(`Visiting ${indexHTML}`);
|
|
28
28
|
return h.file(indexHTML);
|