UNPKG

4.44 kBJavaScriptView Raw
1/*
2
3 ----------------------------------------------------------------------------
4 | qewd-ripple: QEWD-based Middle Tier for Ripple OSI |
5 | |
6 | Copyright (c) 2016-17 Ripple Foundation Community Interest Company |
7 | All rights reserved. |
8 | |
9 | http://rippleosi.org |
10 | Email: code.custodian@rippleosi.org |
11 | |
12 | Author: Rob Tweed, M/Gateway Developments Ltd |
13 | |
14 | Licensed under the Apache License, Version 2.0 (the "License"); |
15 | you may not use this file except in compliance with the License. |
16 | You may obtain a copy of the License at |
17 | |
18 | http://www.apache.org/licenses/LICENSE-2.0 |
19 | |
20 | Unless required by applicable law or agreed to in writing, software |
21 | distributed under the License is distributed on an "AS IS" BASIS, |
22 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
23 | See the License for the specific language governing permissions and |
24 | limitations under the License. |
25 ----------------------------------------------------------------------------
26
27 26 January 2017
28
29*/
30
31var qewd = require('qewd').master;
32
33function 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
113module.exports = {
114 start: start
115};
116
117
118