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

textbook / starter-kit / 17709629101

14 Sep 2025 10:01AM UTC coverage: 62.827% (+0.3%) from 62.566%
17709629101

push

github

textbook
Upgrade JSDOM to v27

46 of 64 branches covered (71.88%)

Branch coverage included in aggregate %.

314 of 509 relevant lines covered (61.69%)

3.78 hits per line

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

75.0
/api/utils/middleware.js
1
import { dirname, join, resolve } from "node:path";
1✔
2
import { fileURLToPath } from "node:url";
1✔
3

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

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

10
const __dirname = dirname(fileURLToPath(import.meta.url));
1✔
11

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

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

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

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

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

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