1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | var qewd = require('qewd').master;
|
32 |
|
33 | function start(config) {
|
34 |
|
35 | var routes = [
|
36 | {
|
37 | path: '/api',
|
38 | module: 'qewd-ripple'
|
39 | }
|
40 | ];
|
41 |
|
42 | if (!config.webServerRootPath) config.webServerRootPath = process.cwd() + '/www';
|
43 | if (!config.database) config.database = {type: 'gtm'};
|
44 | if (!config.serverName) config.serverName = 'RippleOSI QEWD Server';
|
45 | if (!config.managementPassword) config.managementPassword = 'keepThisSecret!';
|
46 |
|
47 | var q = qewd.start(config, routes);
|
48 |
|
49 | if (config.auth0) {
|
50 | var passport = require('passport');
|
51 | var Auth0Strategy = require('passport-auth0');
|
52 |
|
53 | var strategy = new Auth0Strategy({
|
54 | domain: config.auth0.domain,
|
55 | clientID: config.auth0.clientID,
|
56 | clientSecret: config.auth0.clientSecret,
|
57 | callbackURL: config.auth0.callbackURL,
|
58 | },
|
59 | function(accessToken, refreshToken, extraParams, profile, done) {
|
60 | return done(null, profile);
|
61 | }
|
62 | );
|
63 |
|
64 | passport.use(strategy);
|
65 | passport.serializeUser(function(user, done) {
|
66 | done(null, user);
|
67 | });
|
68 | passport.deserializeUser(function(user, done) {
|
69 | done(null, user);
|
70 | });
|
71 |
|
72 | var failURL = config.auth0.failURL || '/fail.html';
|
73 | var callbackPath = config.auth0.callbackPath || '/auth0/token';
|
74 |
|
75 | var app = qewd.intercept().app;
|
76 | app.use(passport.initialize());
|
77 | app.use(passport.session());
|
78 | app.get(callbackPath,
|
79 | passport.authenticate('auth0', { failureRedirect: failURL }),
|
80 | function(req, res) {
|
81 | var message = {
|
82 | type: 'ewd-qoper8-express',
|
83 | expressType: 'auth0-register',
|
84 | application: 'qewd-ripple',
|
85 | params: req.user
|
86 | };
|
87 | q.handleMessage(message, function(response) {
|
88 | console.log('*** auth0-register response: ' + JSON.stringify(response));
|
89 | res.cookie('JSESSIONID', response.message.token);
|
90 | res.redirect(config.auth0.indexURL);
|
91 | });
|
92 | }
|
93 | );
|
94 | q.userDefined['auth0'] = config.auth0;
|
95 | }
|
96 |
|
97 | var pasConfig = {
|
98 | openEHR: {
|
99 | pasModule: 'mysqlPAS',
|
100 | summaryHeadings: ['allergies', 'problems', 'medications', 'contacts', {name: 'transfers', value: true}]
|
101 | }
|
102 | };
|
103 | if (config.ripple && config.ripple.pas) pasConfig = config.ripple.pas;
|
104 |
|
105 | var pas = process.argv[2] || 'openEHR'
|
106 | q.userDefined['rippleUser'] = pasConfig[pas];
|
107 | var mode = 'demo';
|
108 | if (config.ripple && config.ripple.mode) mode = config.ripple.mode;
|
109 | q.userDefined['rippleMode'] = mode;
|
110 |
|
111 | }
|
112 |
|
113 | module.exports = {
|
114 | start: start
|
115 | };
|
116 |
|
117 |
|
118 |
|