-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
245 lines (207 loc) · 10.8 KB
/
app.js
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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
134
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
209
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
238
239
240
241
242
243
244
245
/*********************************************************************************
* The MIT License (MIT) *
* *
* Copyright (c) 2020 KMi, The Open University UK *
* *
* Permission is hereby granted, free of charge, to any person obtaining *
* a copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the Software *
* is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN *
* THE SOFTWARE. *
* *
**********************************************************************************/
/** Author: Michelle Bachler, KMi, The Open University **/
/** Author: Manoharan Ramachandran, KMi, The Open University **/
/** Author: Samantha Colclough, KMi, The Open University **/
/** Author: Kevin Quick, KMi, The Open University **/
/** merged file */
var express = require('express');
var cors = require('cors');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var hbs = require('express-handlebars');
require('console-stamp')(console, { pattern: 'dd/mm/yyyy HH:MM:ss.l' });
var cfg = require('./config.js');
var fileUpload = require('express-fileupload');
var badges = require('./routes/badges');
var issuers = require('./routes/issuers');
var endorsers = require('./routes/endorsers');
var recipients = require('./routes/recipients');
var alignments = require('./routes/alignments');
var evidence = require('./routes/evidence');
var assertions = require('./routes/assertions');
var users = require('./routes/users');
var keys = require('./routes/keys');
var admin = require('./routes/admin');
var maintenance = require('./routes/maintenance');
var pdf = require('./routes/pdf');
var organizations = require('./routes/organizations');
var events = require('./routes/events');
var qualifying = require('./routes/qualifying');
var endorsements = require('./routes/endorsements');
var cfg = require('./config.js');
//Qualichain Specific
var index = require('./routes/index');
var merkle = require('./routes/merkle');
var util = require('./routes/util');
var app = express();
//https://expressjs.com/en/advanced/best-practice-security.html#use-helmet
app.disable('x-powered-by')
/*
CORS STUFF FROM blockcn07 RDF SERVICE - Not sure if needed here - not needed for SERVICE
// allow connections from any browser/domain
// https://github.com/expressjs/cors
//app.use(cors());
var corsOptions = {
origin: '*',
optionsSuccessStatus: 200 // some legacy browsers (IE11, various SmartTVs) choke on 204
}
app.use(cors(corsOptions));
// enable pre-flight across-the-board
app.options('*', cors()) // include before other routes
*/
app.use(fileUpload({
limits: { fileSize: 20971520}, //20MB, 5MB=5242880 //
safeFileNames: true,
abortOnLimit: true,
responseOnLimit: true
}));
app.engine('hbs', hbs({extname: 'hbs', defaultLayout: 'layout', layoutsDir: __dirname + '/views/layouts', partialsDir: __dirname + '/views/layouts/partials'}));
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'hbs');
app.use(logger('dev'));
//app.use(bodyParser.json());
// added for creating badge images as JSON includes image base 64 which can make it big
app.use(bodyParser.json({limit:'50mb', type:'application/json'}));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
// comment out section below for maintenace mode
app.use('/issuers', issuers);
app.use('/endorsers', endorsers);
app.use('/recipients', recipients);
app.use('/alignments', alignments);
app.use('/evidence', evidence);
app.use('/assertions', assertions);
app.use('/users', users);
app.use('/admin', admin);
app.use('/pdf', pdf);
app.use('/organizations', organizations);
app.use('/events', events);
app.use('/qualifying', qualifying);
app.use('/endorsements', endorsements);
app.use('/keys', keys);
app.use('/merkle', merkle);
app.use('/util', util);
// needs to be last
app.use('/badges', badges);
app.use('/', index);
app.use('/images', express.static(__dirname + '/public/images'));
app.use('/badges/images', express.static(__dirname + '/public/images'));
app.use('/badges/view/images', express.static(__dirname + '/public/images'));
app.use('/badges/contract/images', express.static(__dirname + '/public/images'));
app.use('/badges/contract/view/images', express.static(__dirname + '/public/images'));
app.use('/issuers/images', express.static(__dirname + '/public/images'));
app.use('/endorsers/images', express.static(__dirname + '/public/images'));
app.use('/recipients/images', express.static(__dirname + '/public/images'));
app.use('/alignments/images', express.static(__dirname + '/public/images'));
app.use('/evidence/images', express.static(__dirname + '/public/images'));
app.use('/assertions/images', express.static(__dirname + '/public/images'));
app.use('/users/images', express.static(__dirname + '/public/images'));
app.use('/organizations/images', express.static(__dirname + '/public/images'));
app.use('/events/images', express.static(__dirname + '/public/images'));
app.use('/merkle/images', express.static(__dirname + '/public/images'));
app.use('/endorsements/images', express.static(__dirname + '/public/images'));
app.use('/javascripts', express.static(__dirname + '/public/javascripts'));
app.use('/badges/javascripts', express.static(__dirname + '/public/javascripts'));
app.use('/badges/view/javascripts', express.static(__dirname + '/public/javascripts'));
app.use('/badges/contract/javascripts', express.static(__dirname + '/public/javascripts'));
app.use('/badges/contract/view/javascripts', express.static(__dirname + '/public/javascripts'));
app.use('/issuers/javascripts', express.static(__dirname + '/public/javascripts'));
app.use('/endorsers/javascripts', express.static(__dirname + '/public/javascripts'));
app.use('/recipients/javascripts', express.static(__dirname + '/public/javascripts'));
app.use('/alignments/javascripts', express.static(__dirname + '/public/javascripts'));
app.use('/evidence/javascripts', express.static(__dirname + '/public/javascripts'));
app.use('/assertions/javascripts', express.static(__dirname + '/public/javascripts'));
app.use('/users/javascripts', express.static(__dirname + '/public/javascripts'));
app.use('/organizations/javascripts', express.static(__dirname + '/public/javascripts'));
app.use('/events/javascripts', express.static(__dirname + '/public/javascripts'));
app.use('/merkle/javascripts', express.static(__dirname + '/public/javascripts'));
app.use('/endorsements/javascripts', express.static(__dirname + '/public/javascripts'));
app.use('/stylesheets', express.static(__dirname + '/public/stylesheets'));
app.use('/badges/stylesheets', express.static(__dirname + '/public/stylesheets'));
app.use('/badges/view/stylesheets', express.static(__dirname + '/public/stylesheets'));
app.use('/badges/contract/stylesheets', express.static(__dirname + '/public/stylesheets'));
app.use('/badges/contract/view/stylesheets', express.static(__dirname + '/public/stylesheets'));
app.use('/issuers/stylesheets', express.static(__dirname + '/public/stylesheets'));
app.use('/endorsers/stylesheets', express.static(__dirname + '/public/stylesheets'));
app.use('/recipients/stylesheets', express.static(__dirname + '/public/stylesheets'));
app.use('/alignments/stylesheets', express.static(__dirname + '/public/stylesheets'));
app.use('/evidence/stylesheets', express.static(__dirname + '/public/stylesheets'));
app.use('/assertions/stylesheets', express.static(__dirname + '/public/stylesheets'));
app.use('/users/stylesheets', express.static(__dirname + '/public/stylesheets'));
app.use('/organizations/stylesheets', express.static(__dirname + '/public/stylesheets'));
app.use('/events/stylesheets', express.static(__dirname + '/public/stylesheets'));
app.use('/merkle/stylesheets', express.static(__dirname + '/public/stylesheets'));
app.use('/endorsements/stylesheets', express.static(__dirname + '/public/stylesheets'));
app.use('/lib', express.static(__dirname + '/public/lib'));
app.use('/ld', express.static(__dirname + '/public/ld'));
// end comment out section for maintenace mode
// uncomment section for maintenance mode
/*
app.use('/', maintenance);
app.use('/images', express.static(__dirname + '/public/images'));
app.use('/javascripts', express.static(__dirname + '/public/javascripts'));
app.use('/stylesheets', express.static(__dirname + '/public/stylesheets'));
app.use(redirectUnmatched);
function redirectUnmatched(req, res) {
res.redirect(cfg.maintenance_redirect);
}
*/
// end uncomment section mainteance mode
// Falls into this if route not found.
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
res.render('error');
});
var db = require('./db')
// Connect to MySQL on start
db.connect(db.MODE_PRODUCTION, function(err) {
if (err) {
console.log('Unable to connect to MySQL.');
process.exit(1);
} else {
// = 6 minutes?
app.timeout = 240000;
//server.timeout = 120000;/ // = default
app.listen(cfg.express_port, function() {
console.log('Listening on port ' + cfg.express_port + '...');
});
}
})
module.exports = app;