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

textbook / starter-kit / 29691732664

19 Jul 2026 02:53PM UTC coverage: 68.182% (-0.2%) from 68.342%
29691732664

push

github

textbook
Upgrade React Router to v8

31 of 62 branches covered (50.0%)

Branch coverage included in aggregate %.

104 of 136 relevant lines covered (76.47%)

8.6 hits per line

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

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

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

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

9
export const clientRouter = (apiRoot) => {
3✔
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
        });
19
        return router;
3✔
20
};
21

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

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

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

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

48
/**
49
 * Whether the request is a `GET /healthz`
50
 * @param {import("express").Request} req
51
 * @returns {boolean}
52
 */
53
function isHealthcheck(req) {
54
        return req.path === "/healthz" && req.method === "GET";
1✔
55
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc