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

pmcelhaney / counterfact / 6053254142

01 Sep 2023 07:24PM UTC coverage: 85.172% (-0.1%) from 85.316%
6053254142

push

github

web-flow
Merge pull request #546 from pmcelhaney/prep-for-typescript

changes to config files to prepare for conversion to TypeScript

678 of 739 branches covered (0.0%)

Branch coverage included in aggregate %.

1970 of 2370 relevant lines covered (83.12%)

21.17 hits per line

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

95.65
/src/server/koa-middleware.js
1
import koaProxy from "koa-proxy";
2✔
2

2✔
3
const HTTP_STATUS_CODE_OK = 200;
2✔
4

2✔
5
function addCors(ctx, headers) {
16✔
6
  // Always append CORS headers, reflecting back the headers requested if any
16✔
7
  ctx.set("Access-Control-Allow-Origin", headers?.origin || "*");
16✔
8
  ctx.set("Access-Control-Allow-Methods", "GET,HEAD,PUT,POST,DELETE,PATCH");
16✔
9
  ctx.set(
16✔
10
    "Access-Control-Allow-Headers",
16✔
11
    headers?.["access-control-request-headers"],
16✔
12
  );
16✔
13
  ctx.set(
16✔
14
    "Access-Control-Expose-Headers",
16✔
15
    headers?.["access-control-request-headers"],
16✔
16
  );
16✔
17
  ctx.set("Access-Control-Allow-Credentials", "true");
16✔
18
}
16✔
19

2✔
20
export function koaMiddleware(dispatcher, options = {}, proxy = koaProxy) {
2✔
21
  return async function middleware(ctx, next) {
16✔
22
    const { body, headers, method, path, query } = ctx.request;
20✔
23

20✔
24
    if (options.proxyEnabled && options.proxyUrl) {
20✔
25
      return proxy({ host: options.proxyUrl })(ctx, next);
4✔
26
    }
4✔
27

16✔
28
    addCors(ctx, headers);
16✔
29

16✔
30
    // If the method is OPTIONS then always return OK
16✔
31
    if (method === "OPTIONS") {
20!
32
      ctx.status = HTTP_STATUS_CODE_OK;
×
33
    } else {
20✔
34
      const response = await dispatcher.request({
16✔
35
        body,
16✔
36
        headers,
16✔
37
        method,
16✔
38
        path,
16✔
39
        query,
16✔
40
        req: ctx.req,
16✔
41
      });
16✔
42

16✔
43
      /* eslint-disable require-atomic-updates */
16✔
44
      ctx.body = response.body;
16✔
45
      ctx.status = response.status ?? HTTP_STATUS_CODE_OK;
16✔
46
      /* eslint-enable require-atomic-updates */
16✔
47
    }
16✔
48

16✔
49
    return undefined;
16✔
50
  };
16✔
51
}
16✔
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