This repository has been archived by the owner on Mar 12, 2020. It is now read-only.
/
app.js
105 lines (90 loc) · 2.79 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
'use strict';
const express = require('@financial-times/n-internal-tool');
const fixtures = require('./fixtures/fixtures.json');
const fixturesCommercial = require('./fixtures/fixtures-commercial-content');
const fixturesPackageArticle = require('./fixtures/fixtures-article-in-package');
const fixturesVideo = require('./fixtures/fixtures-video');
const fixturesLiveBlog = require('./fixtures/fixures-live-blog.json');
const fixturesLiveBlogClosed = require('./fixtures/fixures-live-blog-closed.json');
const fixturesLiveRollingSplash = require('./fixtures/fixtures-live-rolling-splash.json');
const chalk = require('chalk');
const errorHighlight = chalk.bold.red;
const highlight = chalk.bold.green;
const app = module.exports = express({
name: 'public',
systemCode: 'n-teaser-demo',
withFlags: false,
withHandlebars: true,
withNavigation: false,
withAnonMiddleware: false,
hasHeadCss: false,
layoutsDir: 'demos/templates',
viewsDirectory: '/demos/templates',
partialsDirectory: process.cwd(),
directory: process.cwd(),
demo: true,
s3o: false,
helpers: {
nTeaserPresenter: require('../').presenter,
packageTeaserPresenter: require('../').presenter
}
});
app.get('/package-article', (req, res) => {
res.render('demo-package-article', Object.assign({
title: 'Content from package teasers',
layout: 'demo-layout',
}, fixturesPackageArticle));
});
app.get('/video', (req, res) => {
res.render('demo', Object.assign({
title: 'Video teasers',
layout: 'demo-layout',
}, fixturesVideo));
});
app.get('/commercial', (req, res) => {
res.render('demo-commercial-content', Object.assign({
title: 'Commercial teasers',
layout: 'demo-layout',
}, fixturesCommercial));
});
app.get('/article', (req, res) => {
res.render('demo', Object.assign({
title: 'Article teasers',
layout: 'demo-layout',
}, fixtures));
});
app.get('/live-blog', (req, res) => {
res.render('demo', Object.assign({
title: 'Live blog teasers',
layout: 'demo-layout',
}, fixturesLiveBlog));
});
app.get('/live-blog-closed', (req, res) => {
res.render('demo', Object.assign({
title: 'Closed live blog teasers',
layout: 'demo-layout',
}, fixturesLiveBlogClosed));
});
app.get('/live-rolling-splash', (req, res) => {
res.render('demo', Object.assign({
title: 'Live package rolling splash',
layout: 'demo-layout',
}, fixturesLiveRollingSplash));
});
function runPa11yTests () {
const spawn = require('child_process').spawn;
const pa11y = spawn('pa11y-ci');
pa11y.stdout.on('data', (data) => {
console.log(highlight(`${data}`)); //eslint-disable-line
});
pa11y.stderr.on('data', (error) => {
console.log(errorHighlight(`${error}`)); //eslint-disable-line
});
pa11y.on('close', (code) => {
process.exit(code);
});
}
const listen = app.listen(5005);
if (process.env.PA11Y === 'true') {
listen.then(runPa11yTests);
}