• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pmcelhaney / counterfact / 6629131525

24 Oct 2023 03:32PM UTC coverage: 82.754% (-3.4%) from 86.129%
6629131525

Pull #599

github

pmcelhaney
watch the OpenAPI and regenerate types when it changes
Pull Request #599: don't expose moduleLoader

736 of 822 branches covered (0.0%)

Branch coverage included in aggregate %.

306 of 306 new or added lines in 7 files covered. (100.0%)

2383 of 2947 relevant lines covered (80.86%)

36.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/server/page-middleware.ts
1
import nodePath from "node:path";
×
2
import { fileURLToPath } from "node:url";
×
3

×
4
import createDebug from "debug";
×
5
import Handlebars from "handlebars";
×
6
import type Koa from "koa";
×
7

×
8
import { readFile } from "../util/read-file.js";
×
9

×
10
// eslint-disable-next-line no-underscore-dangle
×
11
const __dirname = nodePath.dirname(fileURLToPath(import.meta.url));
×
12

×
13
const debug = createDebug("counterfact:server:page-middleware");
×
14

×
15
Handlebars.registerHelper("escape_route", (route: string) =>
×
16
  route.replaceAll(/[^\w/]/gu, "-"),
×
17
);
×
18

×
19
export function pageMiddleware(
×
20
  pathname: string,
×
21
  templateName: string,
×
22
  locals: { [key: string]: unknown },
×
23
) {
×
24
  return async (ctx: Koa.ExtendableContext, next: Koa.Next) => {
×
25
    const pathToHandlebarsTemplate = nodePath
×
26
      .join(__dirname, `../client/${templateName}.html.hbs`)
×
27
      .replaceAll("\\", "/");
×
28

×
29
    debug("pathToHandlebarsTemplate: %s", pathToHandlebarsTemplate);
×
30

×
31
    const render = Handlebars.compile(await readFile(pathToHandlebarsTemplate));
×
32

×
33
    if (ctx.URL.pathname === pathname) {
×
34
      ctx.body = render(locals);
×
35

×
36
      return;
×
37
    }
×
38

×
39
    // eslint-disable-next-line  n/callback-return
×
40
    await next();
×
41
  };
×
42
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc