Skip to content

Commit

Permalink
More tracing of brochure requests
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmerfield committed Sep 9, 2021
1 parent 0eba84f commit 8469f78
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/brochure/routes/index.js
Expand Up @@ -4,7 +4,7 @@ var finder = require("finder");
var tex = require("./tools/tex");
var config = require("config");
var titleFromSlug = require("helper/titleFromSlug");

var trace = require('helper/trace');
var TITLES = {
"how": "How it works",
"terms": "Terms of use",
Expand All @@ -17,9 +17,12 @@ var TITLES = {
"who": "Who uses Blot?",
"developers": "Developer guide",
"json-feed": "JSON feed",
"posts-tagged": "A page with posts with a particular tag"
"posts-tagged": "A page with posts with a particular tag",
};

brochure.use(trace("inside routes sub app"));


if (config.cache) {
// Minifies HTML
brochure.use(require("./tools/minify-html"));
Expand All @@ -28,6 +31,8 @@ if (config.cache) {
brochure.use(require("./tools/inline-css"));
}



brochure.get(["/how/format/*"], function (req, res, next) {
res.locals["show-on-this-page"] = true;
next();
Expand Down Expand Up @@ -107,6 +112,7 @@ brochure.use("/account", function (req, res, next) {
next();
});


brochure.get("/", require("./featured"));

brochure.get("/", function (req, res, next) {
Expand Down Expand Up @@ -138,6 +144,8 @@ brochure.use("/how/guides/domain", function (req, res, next) {
next();
});

brochure.use(trace("calling render"));

brochure.use(function (req, res) {
res.render(trimLeadingAndTrailingSlash(req.path));
});
Expand Down
4 changes: 4 additions & 0 deletions app/brochure/routes/tools/on-this-page.js
Expand Up @@ -7,6 +7,7 @@ module.exports = function onThisPage(req, res, next) {
const send = res.send;

res.send = function (string) {
req.trace('starting onThisPage send');
const html = string instanceof Buffer ? string.toString() : string;
const $ = cheerio.load(html, { decodeEntities: false });
$("h2:not(h1 + h2),h3").each((i, el) => {
Expand All @@ -17,10 +18,12 @@ module.exports = function onThisPage(req, res, next) {
$(el).html(`<a href="#${id}">${innerHTML}</a>`);
});

req.trace('finished onThisPage send');
send.call(this, $.html());
};

res.render = function (view, locals, partials) {
req.trace('starting onThisPage render');
const html = loadView(req.app.get("views"), view);

if (!html) return next();
Expand All @@ -39,6 +42,7 @@ module.exports = function onThisPage(req, res, next) {
res.locals.headers = headers;
}

req.trace('finished onThisPage render');
render.call(this, view, locals, partials);
};

Expand Down
3 changes: 3 additions & 0 deletions app/brochure/routes/tools/tex.js
Expand Up @@ -7,6 +7,8 @@ module.exports = function render_tex(req, res, next) {
var send = res.send;

res.send = function (string) {
req.trace('starting tex render');

var html = string instanceof Buffer ? string.toString() : string;

var $ = cheerio.load(html, { decodeEntities: false });
Expand Down Expand Up @@ -74,6 +76,7 @@ module.exports = function render_tex(req, res, next) {

html = $.html();

req.trace('finished tex render');
send.call(this, html);
};

Expand Down
2 changes: 2 additions & 0 deletions app/brochure/routes/tools/typeset.js
Expand Up @@ -4,10 +4,12 @@ module.exports = function typeset(req, res, next) {
var send = res.send;

res.send = function (string) {
req.trace('Starting typeset');
var html = string instanceof Buffer ? string.toString() : string;

html = Typeset(html, { disable: ["hyphenate"], ignore: "textarea, input" });

req.trace('finished typeset');
send.call(this, html);
};

Expand Down

0 comments on commit 8469f78

Please sign in to comment.