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

pmcelhaney / counterfact / 9310610020

30 May 2024 11:42PM UTC coverage: 87.241%. Remained the same
9310610020

Pull #902

github

web-flow
Update dependency eslint to v9
Pull Request #902: Update dependency eslint to v9

984 of 1094 branches covered (89.95%)

Branch coverage included in aggregate %.

3228 of 3734 relevant lines covered (86.45%)

44.33 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(
×
24
    openapiMiddleware(
×
25
      config.openApiPath,
×
26
      `//localhost:${config.port}${config.routePrefix}`,
×
27
    ),
×
28
  );
×
29

×
30
  app.use(
×
31
    koaSwagger({
×
32
      routePrefix: "/counterfact/swagger",
×
33

×
34
      swaggerOptions: {
×
35
        url: "/counterfact/openapi",
×
36
      },
×
37
    }),
×
38
  );
×
39

×
40
  debug("basePath: %s", config.basePath);
×
41
  debug("routes", registry.routes);
×
42

×
43
  app.use(
×
44
    pageMiddleware("/counterfact/", "index", {
×
45
      basePath: config.basePath,
×
46
      methods: ["get", "post", "put", "delete", "patch"],
×
47

×
48
      openApiHref: config.openApiPath.includes("://")
×
49
        ? config.openApiPath
×
50
        : pathToFileURL(config.openApiPath).href,
×
51

×
52
      openApiPath: config.openApiPath,
×
53

×
54
      get routes() {
×
55
        return registry.routes;
×
56
      },
×
57
    }),
×
58
  );
×
59

×
60
  app.use(async (ctx, next) => {
×
61
    if (ctx.URL.pathname === "/counterfact") {
×
62
      ctx.redirect("/counterfact/");
×
63

×
64
      return;
×
65
    }
×
66

×
67
    // eslint-disable-next-line  n/callback-return
×
68
    await next();
×
69
  });
×
70

×
71
  app.use(
×
72
    pageMiddleware("/counterfact/rapidoc", "rapi-doc", {
×
73
      basePath: config.basePath,
×
74

×
75
      get routes() {
×
76
        return registry.routes;
×
77
      },
×
78
    }),
×
79
  );
×
80

×
81
  app.use(bodyParser());
×
82

×
83
  app.use(koaMiddleware);
×
84

×
85
  return app;
×
86
}
×
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