(
req,
res,
dirAbs,
staticMiddleware,
injectionOpts = {},
rejectPrefixes = [],
basePath = "/",
)
| 544 | } |
| 545 | |
| 546 | async function handleStatic( |
| 547 | req, |
| 548 | res, |
| 549 | dirAbs, |
| 550 | staticMiddleware, |
| 551 | injectionOpts = {}, |
| 552 | rejectPrefixes = [], |
| 553 | basePath = "/", |
| 554 | ) { |
| 555 | const urlPath = parseUrlPath(req, res); |
| 556 | if (urlPath === null) return; |
| 557 | |
| 558 | if (!isMountedPath(urlPath, basePath)) { |
| 559 | if (matchesAnyPrefix(urlPath, rejectPrefixes)) { |
| 560 | rejectUnavailable(res); |
| 561 | return; |
| 562 | } |
| 563 | if (!redirectToMountedPath(req, res, urlPath, basePath)) notFound(res); |
| 564 | return; |
| 565 | } |
| 566 | |
| 567 | const mountedUrl = stripBasePathFromUrl(req.url ?? "/", basePath); |
| 568 | const mountedPath = parseUrlPath({ ...req, url: mountedUrl }, res); |
| 569 | if (mountedPath === null) return; |
| 570 | |
| 571 | const injectRuntimeConfig = needsRuntimeInjection(injectionOpts); |
| 572 | const indexPath = resolve(dirAbs, "index.html"); |
| 573 | |
| 574 | if ( |
| 575 | injectRuntimeConfig && |
| 576 | isGetOrHead(req) && |
| 577 | (mountedPath === "/" || mountedPath === "/index.html") |
| 578 | ) { |
| 579 | if (await serveInjectedIndexHtml(req, res, indexPath, injectionOpts)) |
| 580 | return; |
| 581 | } |
| 582 | |
| 583 | const mountedReq = Object.create(req); |
| 584 | mountedReq.url = mountedUrl; |
| 585 | |
| 586 | staticMiddleware(mountedReq, res, async () => { |
| 587 | if (matchesAnyPrefix(mountedPath, rejectPrefixes)) { |
| 588 | rejectUnavailable(res); |
| 589 | return; |
| 590 | } |
| 591 | |
| 592 | if (isGetOrHead(req) && !looksLikeAssetRequest(mountedPath)) { |
| 593 | if (await serveInjectedIndexHtml(req, res, indexPath, injectionOpts)) { |
| 594 | return; |
| 595 | } |
| 596 | } |
| 597 | |
| 598 | notFound(res); |
| 599 | }); |
| 600 | } |
| 601 | |
| 602 | // ───────────────────────────────────────────────────────────────────────────── |
| 603 | // Server |
no test coverage detected