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

textbook / starter-kit / 16538276872

26 Jul 2025 09:08AM UTC coverage: 80.909% (+0.8%) from 80.142%
16538276872

push

github

textbook
Support Docker/Kubernetes healthchecks

46 of 63 branches covered (73.02%)

Branch coverage included in aggregate %.

11 of 14 new or added lines in 1 file covered. (78.57%)

310 of 377 relevant lines covered (82.23%)

5.09 hits per line

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

74.14
/api/utils/middleware.js
1
import { join, resolve } from "node:path";
1✔
2

3
import express, { Router } from "express";
1✔
4
import helmet from "helmet";
1✔
5
import morgan from "morgan";
1✔
6

7
import logger from "./logger.js";
1✔
8

9
export const clientRouter = (apiRoot) => {
1✔
10
        const staticDir = resolve(import.meta.dirname, "..", "static");
3✔
11
        const router = Router();
3✔
12
        router.use(express.static(staticDir));
3✔
13
        router.use((req, res, next) => {
3✔
14
                if (req.method === "GET" && !req.url.startsWith(apiRoot)) {
2!
15
                        return res.sendFile(join(staticDir, "index.html"));
×
16
                }
×
17
                next();
2✔
18
        });
3✔
19
        return router;
3✔
20
};
3✔
21

22
export const configuredHelmet = () => helmet({ contentSecurityPolicy: false });
1✔
23

24
export const configuredMorgan = () =>
1✔
25
        morgan("dev", {
3✔
26
                skip(req) {
3✔
27
                        return "container-healthcheck" in req.headers && isHealthcheck(req);
8✔
28
                },
3✔
29
                stream: { write: (message) => logger.info(message.trim()) },
3✔
30
        });
1✔
31

32
export const httpsOnly = () => (req, res, next) => {
1✔
NEW
33
        if (req.secure || isHealthcheck(req)) {
×
NEW
34
                return next();
×
35
        }
×
NEW
36
        res.redirect(301, `https://${req.headers.host}${req.originalUrl}`);
×
37
};
×
38

39
/** @type {() => import("express").ErrorRequestHandler} */
1✔
40
export const logErrors = () => (err, _, res, next) => {
1✔
41
        if (res.headersSent) {
×
42
                return next(err);
×
43
        }
×
44
        logger.error("%O", err);
×
45
        res.sendStatus(500);
×
46
};
×
47

48
/**
1✔
49
 * Whether the request is a `GET /healthz`
1✔
50
 * @param {import("express").Request} req
1✔
51
 * @returns {boolean}
1✔
52
 */
1✔
53
function isHealthcheck(req) {
1✔
54
        return req.path === "/healthz" && req.method === "GET";
1✔
55
}
1✔
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