(
req,
res,
dirAbs,
staticMiddleware,
injectionOpts = {},
rejectPrefixes = [],
basePath = "/",
)
| 607 | } |
| 608 | |
| 609 | async function handleStatic( |
| 610 | req, |
| 611 | res, |
| 612 | dirAbs, |
| 613 | staticMiddleware, |
| 614 | injectionOpts = {}, |
| 615 | rejectPrefixes = [], |
| 616 | basePath = "/", |
| 617 | ) { |
| 618 | const urlPath = parseUrlPath(req, res); |
| 619 | if (urlPath === null) return; |
| 620 | |
| 621 | if (!isMountedPath(urlPath, basePath)) { |
| 622 | if (matchesAnyPrefix(urlPath, rejectPrefixes)) { |
| 623 | rejectUnavailable(res); |
| 624 | return; |
| 625 | } |
| 626 | if (!redirectToMountedPath(req, res, urlPath, basePath)) notFound(res); |
| 627 | return; |
| 628 | } |
| 629 | |
| 630 | const mountedUrl = stripBasePathFromUrl(req.url ?? "/", basePath); |
| 631 | const mountedPath = parseUrlPath({ ...req, url: mountedUrl }, res); |
| 632 | if (mountedPath === null) return; |
| 633 | |
| 634 | const injectRuntimeConfig = needsRuntimeInjection(injectionOpts); |
| 635 | const indexPath = resolve(dirAbs, "index.html"); |
| 636 | |
| 637 | if ( |
| 638 | injectRuntimeConfig && |
| 639 | isGetOrHead(req) && |
| 640 | (mountedPath === "/" || mountedPath === "/index.html") |
| 641 | ) { |
| 642 | if (await serveInjectedIndexHtml(req, res, indexPath, injectionOpts)) |
| 643 | return; |
| 644 | } |
| 645 | |
| 646 | const mountedReq = Object.create(req); |
| 647 | mountedReq.url = mountedUrl; |
| 648 | |
| 649 | staticMiddleware(mountedReq, res, async () => { |
| 650 | if (matchesAnyPrefix(mountedPath, rejectPrefixes)) { |
| 651 | rejectUnavailable(res); |
| 652 | return; |
| 653 | } |
| 654 | |
| 655 | if (isGetOrHead(req) && !looksLikeAssetRequest(mountedPath)) { |
| 656 | if (await serveInjectedIndexHtml(req, res, indexPath, injectionOpts)) { |
| 657 | return; |
| 658 | } |
| 659 | } |
| 660 | |
| 661 | notFound(res); |
| 662 | }); |
| 663 | } |
| 664 | |
| 665 | // ───────────────────────────────────────────────────────────────────────────── |
| 666 | // Server |
no test coverage detected