forked from external-repos/pa11y-dashboard
Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
3b76433cf3 | ||
![]() |
f3462f0c1e | ||
![]() |
9dbee59746 | ||
![]() |
321d7bb6ba | ||
![]() |
4fd73bcf2f |
@@ -5,9 +5,19 @@ root = true
|
|||||||
[*]
|
[*]
|
||||||
charset = utf-8
|
charset = utf-8
|
||||||
end_of_line = lf
|
end_of_line = lf
|
||||||
insert_final_newline = true
|
indent_size = 4
|
||||||
indent_style = tab
|
indent_style = tab
|
||||||
|
insert_final_newline = true
|
||||||
trim_trailing_whitespace = true
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
[*.md]
|
[*.md]
|
||||||
|
indent_style = spaces
|
||||||
trim_trailing_whitespace = false
|
trim_trailing_whitespace = false
|
||||||
|
|
||||||
|
[*.yml]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
|
||||||
|
[package.json]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
@@ -1,5 +1,10 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 4.2.0 (2022-03-30)
|
||||||
|
|
||||||
|
* Add request logging for easier debugging
|
||||||
|
* Dependencies update
|
||||||
|
|
||||||
## 4.1.0 (2021-11-26)
|
## 4.1.0 (2021-11-26)
|
||||||
|
|
||||||
* Add support for new WCAG 2.1 rules and remove all references to Section 508.
|
* Add support for new WCAG 2.1 rules and remove all references to Section 508.
|
||||||
|
78
app.js
78
app.js
@@ -20,6 +20,8 @@ const createClient = require('pa11y-webservice-client-node');
|
|||||||
const EventEmitter = require('events').EventEmitter;
|
const EventEmitter = require('events').EventEmitter;
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const hbs = require('express-hbs');
|
const hbs = require('express-hbs');
|
||||||
|
const morgan = require('morgan');
|
||||||
|
const {nanoid} = require('nanoid');
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
const pkg = require('./package.json');
|
const pkg = require('./package.json');
|
||||||
|
|
||||||
@@ -35,14 +37,57 @@ function initApp(config, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const app = new EventEmitter();
|
const app = new EventEmitter();
|
||||||
|
|
||||||
app.address = null;
|
app.address = null;
|
||||||
app.express = express();
|
app.express = express();
|
||||||
app.server = http.createServer(app.express);
|
app.server = http.createServer(app.express);
|
||||||
app.webservice = createClient(webserviceUrl);
|
app.webservice = createClient(webserviceUrl);
|
||||||
|
|
||||||
|
loadMiddleware(app);
|
||||||
|
|
||||||
|
// View engine
|
||||||
|
loadViewEngine(app, config);
|
||||||
|
|
||||||
|
// Load routes
|
||||||
|
loadRoutes(app, config);
|
||||||
|
|
||||||
|
// Error handling
|
||||||
|
loadErrorHandling(app, config, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get default configurations
|
||||||
|
function defaultConfig(config) {
|
||||||
|
if (typeof config.noindex !== 'boolean') {
|
||||||
|
config.noindex = true;
|
||||||
|
}
|
||||||
|
if (typeof config.readonly !== 'boolean') {
|
||||||
|
config.readonly = false;
|
||||||
|
}
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadMiddleware(app) {
|
||||||
// Compression
|
// Compression
|
||||||
app.express.use(compression());
|
app.express.use(compression());
|
||||||
|
|
||||||
|
// Adds an ID to every request, used later for logging
|
||||||
|
app.express.use(addRequestId);
|
||||||
|
|
||||||
|
// Logging middleware
|
||||||
|
morgan.token('id', request => {
|
||||||
|
return request.id;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Log the start of all HTTP requests
|
||||||
|
const startLog = '[:date[iso] #:id] Started :method :url for :remote-addr';
|
||||||
|
// Immediate: true is required to log the request
|
||||||
|
// before the response happens
|
||||||
|
app.express.use(morgan(startLog, {immediate: true}));
|
||||||
|
|
||||||
|
// Log the end of all HTTP requests
|
||||||
|
const endLog = '[:date[iso] #:id] Completed :status :res[content-length] in :response-time ms';
|
||||||
|
app.express.use(morgan(endLog));
|
||||||
|
|
||||||
// Public files
|
// Public files
|
||||||
app.express.use(express.static(`${__dirname}/public`, {
|
app.express.use(express.static(`${__dirname}/public`, {
|
||||||
maxAge: (process.env.NODE_ENV === 'production' ? 604800000 : 0)
|
maxAge: (process.env.NODE_ENV === 'production' ? 604800000 : 0)
|
||||||
@@ -53,8 +98,9 @@ function initApp(config, callback) {
|
|||||||
app.express.use(bodyParser.urlencoded({
|
app.express.use(bodyParser.urlencoded({
|
||||||
extended: true
|
extended: true
|
||||||
}));
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
// View engine
|
function loadViewEngine(app, config) {
|
||||||
app.express.engine('html', hbs.express4({
|
app.express.engine('html', hbs.express4({
|
||||||
extname: '.html',
|
extname: '.html',
|
||||||
contentHelperName: 'content',
|
contentHelperName: 'content',
|
||||||
@@ -89,10 +135,16 @@ function initApp(config, callback) {
|
|||||||
response.locals.host = request.hostname;
|
response.locals.host = request.hostname;
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Load routes
|
function loadRoutes(app, config) {
|
||||||
|
// Because there's some overlap between the different routes,
|
||||||
|
// they have to be loaded in a specific order in order to avoid
|
||||||
|
// passing mongo the wrong id which would result in
|
||||||
|
// "ObjectID generation failed." errors (e.g. #277)
|
||||||
require('./route/index')(app);
|
require('./route/index')(app);
|
||||||
require('./route/result/download')(app);
|
require('./route/result/download')(app);
|
||||||
|
|
||||||
if (!config.readonly) {
|
if (!config.readonly) {
|
||||||
require('./route/new')(app);
|
require('./route/new')(app);
|
||||||
require('./route/task/delete')(app);
|
require('./route/task/delete')(app);
|
||||||
@@ -101,12 +153,14 @@ function initApp(config, callback) {
|
|||||||
require('./route/task/ignore')(app);
|
require('./route/task/ignore')(app);
|
||||||
require('./route/task/unignore')(app);
|
require('./route/task/unignore')(app);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Needs to be loaded after `/route/new`
|
// Needs to be loaded after `/route/new`
|
||||||
require('./route/task/index')(app);
|
require('./route/task/index')(app);
|
||||||
// Needs to be loaded after `/route/task/edit`
|
// Needs to be loaded after `/route/task/edit`
|
||||||
require('./route/result/index')(app);
|
require('./route/result/index')(app);
|
||||||
|
}
|
||||||
|
|
||||||
// Error handling
|
function loadErrorHandling(app, config, callback) {
|
||||||
app.express.get('*', (request, response) => {
|
app.express.get('*', (request, response) => {
|
||||||
response.status(404);
|
response.status(404);
|
||||||
response.render('404');
|
response.render('404');
|
||||||
@@ -129,16 +183,14 @@ function initApp(config, callback) {
|
|||||||
app.address = `http://${address.address}:${address.port}`;
|
app.address = `http://${address.address}:${address.port}`;
|
||||||
callback(error, app);
|
callback(error, app);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get default configurations
|
// Express middleware
|
||||||
function defaultConfig(config) {
|
function addRequestId(request, response, next) {
|
||||||
if (typeof config.noindex !== 'boolean') {
|
// Create a random request (nano)id, 10 characters long
|
||||||
config.noindex = true;
|
// Nano ids are [0-9A-Za-z_-] so chance of collision is 1 in 64^10
|
||||||
}
|
// If a site has so much traffic that this chance is too high
|
||||||
if (typeof config.readonly !== 'boolean') {
|
// we probably have worse things to worry about
|
||||||
config.readonly = false;
|
request.id = nanoid(10);
|
||||||
}
|
next();
|
||||||
return config;
|
|
||||||
}
|
}
|
||||||
|
14
package.json
14
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "pa11y-dashboard",
|
"name": "pa11y-dashboard",
|
||||||
"version": "4.1.0",
|
"version": "4.2.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "Pa11y Dashboard is a visual web interface to the Pa11y accessibility reporter",
|
"description": "Pa11y Dashboard is a visual web interface to the Pa11y accessibility reporter",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@@ -24,16 +24,18 @@
|
|||||||
"node": ">=12 <16"
|
"node": ">=12 <16"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"body-parser": "~1.19.0",
|
"body-parser": "~1.19.2",
|
||||||
"compression": "~1.7.4",
|
"compression": "~1.7.4",
|
||||||
"express": "~4.17.1",
|
"express": "~4.17.3",
|
||||||
"express-hbs": "~2.4.0",
|
"express-hbs": "~2.4.0",
|
||||||
"http-headers": "~3.0.2",
|
"http-headers": "~3.0.2",
|
||||||
"kleur": "~4.1.4",
|
"kleur": "~4.1.4",
|
||||||
"moment": "~2.29.1",
|
"moment": "~2.29.1",
|
||||||
"pa11y-webservice": "~4.0.0",
|
"morgan": "~1.10.0",
|
||||||
|
"nanoid": "~3.3.2",
|
||||||
|
"pa11y-webservice": "~4.0.1",
|
||||||
"pa11y-webservice-client-node": "~3.0.0",
|
"pa11y-webservice-client-node": "~3.0.0",
|
||||||
"underscore": "~1.13.1"
|
"underscore": "~1.13.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"bower": "^1.8.13",
|
"bower": "^1.8.13",
|
||||||
@@ -41,7 +43,7 @@
|
|||||||
"eslint": "^7.27.0",
|
"eslint": "^7.27.0",
|
||||||
"less": "^3.11.1",
|
"less": "^3.11.1",
|
||||||
"mocha": "^8.4.0",
|
"mocha": "^8.4.0",
|
||||||
"pa11y-lint-config": "^1.2.1",
|
"pa11y-lint-config": "^2.0.0",
|
||||||
"proclaim": "^3.6.0",
|
"proclaim": "^3.6.0",
|
||||||
"request": "^2.88.2",
|
"request": "^2.88.2",
|
||||||
"uglify-js": "^3.11.0"
|
"uglify-js": "^3.11.0"
|
||||||
|
Reference in New Issue
Block a user