This repository was archived by the owner on Jul 3, 2023. It is now read-only.
forked from pa11y/pa11y-webservice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
128 lines (110 loc) · 3.34 KB
/
app.js
File metadata and controls
128 lines (110 loc) · 3.34 KB
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
// This file is part of Pa11y Webservice.
//
// Pa11y Webservice is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Pa11y Webservice is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Pa11y Webservice. If not, see <http://www.gnu.org/licenses/>.
'use strict';
const async = require('async');
const Hapi = require('@hapi/hapi');
const {MongoClient} = require('mongodb');
module.exports = initApp;
// Initialise the application
function initApp(config, callback) {
const app = module.exports = {
server: new Hapi.Server({
host: config.host,
port: config.port
}),
database: null,
model: {},
config: config
};
async.series([
next => {
/* eslint camelcase: 'off' */
const client = new MongoClient(config.database_url);
client.connect(function(err) {
if (err) {
console.log('Error connecting to MongoDB:');
console.log(JSON.stringify(err));
return next(err);
}
console.log('Connected successfully to server');
const db = client.db(config.database);
app.db = db;
next(err);
});
},
next => {
require('./model/result')(app, (error, model) => {
app.model.result = model;
next(error);
});
},
next => {
require('./model/axeResult')(app, (error, model) => {
app.model.axeresult = model;
next(error);
});
},
next => {
require('./model/browserstack/task')(app, (error, model) => {
app.model.bstack_task = model;
next(error);
});
},
next => {
require('./model/browserstack/task')(app, (error, model) => {
app.model.bstack_result = model;
next(error);
});
},
next => {
require('./model/task')(app, (error, model) => {
app.model.task = model;
next(error);
});
},
next => {
require('./model/browserstack/axeTasks')(app, (error, model) => {
app.model.axeTask = model;
next(error);
});
},
next => {
if (!config.dbOnly && process.env.NODE_ENV !== 'test') {
require('./task/pa11y')(config, app);
}
next();
},
next => {
if (config.dbOnly) {
return next();
}
require('./route/index')(app);
require('./route/tasks')(app);
require('./route/task')(app);
require('./route/browserstack/task')(app);
require('./route/browserstack/api')(app);
require('./route/browserstack/download')(app);
app.server.start()
.then(
() => next(),
error => next(error)
);
app.server.events.on('response', function (request) {
console.log(request.info.remoteAddress + ': ' + request.method.toUpperCase() + ' ' + request.path + ' --> ' + request.response.statusCode);
});
console.log(`Server running at: ${app.server.info.uri}`);
}
], error => callback(error, app));
}