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

pmcelhaney / counterfact / 6629231258

24 Oct 2023 03:40PM UTC coverage: 82.644% (-3.5%) from 86.129%
6629231258

Pull #599

github

pmcelhaney
changesets for two new features
Pull Request #599: don't expose moduleLoader

736 of 822 branches covered (0.0%)

Branch coverage included in aggregate %.

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

2383 of 2952 relevant lines covered (80.72%)

36.84 hits per line

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

0.0
/src/server/create-koa-app.ts
1
import { pathToFileURL } from "node:url";
×
2

×
3
import createDebug from "debug";
×
4
import Koa from "koa";
×
5
import bodyParser from "koa-bodyparser";
×
6
import { koaSwagger } from "koa2-swagger-ui";
×
7

×
8
import type { Config } from "./config.js";
×
9
import { openapiMiddleware } from "./openapi-middleware.js";
×
10
import { pageMiddleware } from "./page-middleware.js";
×
11
import type { Registry } from "./registry.js";
×
12

×
13
const debug = createDebug("counterfact:server:create-koa-app");
×
14

×
15
// eslint-disable-next-line max-statements
×
16
export function createKoaApp(
×
17
  registry: Registry,
×
18
  koaMiddleware: Koa.Middleware,
×
19
  config: Config,
×
20
) {
×
21
  const app = new Koa();
×
22

×
23
  app.use(openapiMiddleware(config.openApiPath, `//localhost:${config.port}`));
×
24

×
25
  app.use(
×
26
    koaSwagger({
×
27
      routePrefix: "/counterfact/swagger",
×
28

×
29
      swaggerOptions: {
×
30
        url: "/counterfact/openapi",
×
31
      },
×
32
    }),
×
33
  );
×
34

×
35
  debug("basePath: %s", config.basePath);
×
36
  debug("routes", registry.routes);
×
37

×
38
  app.use(
×
39
    pageMiddleware("/counterfact/", "index", {
×
40
      basePath: config.basePath,
×
41
      methods: ["get", "post", "put", "delete", "patch"],
×
42

×
43
      openApiHref: config.openApiPath.includes("://")
×
44
        ? config.openApiPath
×
45
        : pathToFileURL(config.openApiPath).href,
×
46

×
47
      openApiPath: config.openApiPath,
×
48

×
49
      get routes() {
×
50
        return registry.routes;
×
51
      },
×
52
    }),
×
53
  );
×
54

×
55
  app.use(async (ctx, next) => {
×
56
    if (ctx.URL.pathname === "/counterfact") {
×
57
      ctx.redirect("/counterfact/");
×
58

×
59
      return;
×
60
    }
×
61

×
62
    // eslint-disable-next-line  n/callback-return
×
63
    await next();
×
64
  });
×
65

×
66
  app.use(
×
67
    pageMiddleware("/counterfact/rapidoc", "rapi-doc", {
×
68
      basePath: config.basePath,
×
69

×
70
      get routes() {
×
71
        return registry.routes;
×
72
      },
×
73
    }),
×
74
  );
×
75

×
76
  app.use(bodyParser());
×
77

×
78
  app.use(koaMiddleware);
×
79

×
80
  return app;
×
81
}
×
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

© 2026 Coveralls, Inc