astro
Version:
Astro is a modern site builder with web best practices, performance, and DX front-of-mind.
33 lines (32 loc) • 1.24 kB
JavaScript
import { getAmbientManifest } from "../manifest/ambient.js";
import { getRenderOptions } from "../app/render-options.js";
import { handleRequest } from "../routing/handler.js";
import { FetchState } from "./fetch-state.js";
/**
* The default request handler for `BaseApp`. Stateless: builds the
* per-request `FetchState` from the manifest and delegates to
* `handleRequest`.
*
* The export path (`astro/app/fetch/default-handler`), the class name, and
* no-arg constructibility are baked into generated builds
* (`core/fetch/vite-plugin.ts` emits `new DefaultFetchHandler()`), so all
* three survive.
*/
export class DefaultFetchHandler {
#manifest;
/**
* `BaseApp` passes itself so states resolve that app's manifest ahead of
* the ambient one; generated builds construct the handler with no
* arguments and use the ambient manifest.
*/
constructor(app) {
this.#manifest = app?.manifest;
}
fetch = (request) => {
const options = getRenderOptions(request);
// Ambient-only manifest resolution: the render-options record
// carries only genuine `render()` inputs — never a manifest.
const manifest = this.#manifest ?? getAmbientManifest();
return handleRequest(new FetchState(manifest, request, options));
};
}