astro
Version:
Astro is a modern site builder with web best practices, performance, and DX front-of-mind.
55 lines (54 loc) • 1.69 kB
JavaScript
import { req } from "../messages/runtime.js";
import { matchRoute as devMatchRoute } from "../routing/dev.js";
import { BaseApp } from "./base.js";
/**
* The shared thin dev facade: used by BOTH dev paths —
* the workerd / non-runnable dev entrypoint (`entrypoints/virtual/dev.ts`)
* and the runnable dev server (`vite-plugin-app/createAstroServerApp.ts`).
* Everything environment-specific (module loading, error strategy, request
* logging behavior) comes from the `RenderEnvironment` record registered on
* the manifest before construction, and the runnable dev server's HTTP glue
* lives in `vite-plugin-app/handle-request.ts`.
*/
export class DevFacadeApp extends BaseApp {
constructor(manifest, streaming = true) {
super(manifest, streaming);
}
isDev() {
return true;
}
/** Dev always allows prerendered routes to match. */
match(request) {
return super.match(request, true);
}
/**
* A matching route function for the development server. Contrary to
* `.match`, this resolves props and params, returning the correct route
* based on priority and segments, plus the resolved pathname.
*/
async devMatch(pathname, { prerenderOnly } = {}) {
if (pathname === undefined) {
return undefined;
}
const matchedRoute = await devMatchRoute(this.manifest, pathname, { prerenderOnly });
if (!matchedRoute) {
return undefined;
}
return {
routeData: matchedRoute.route,
resolvedPathname: matchedRoute.resolvedPathname
};
}
logRequest({ pathname, method, statusCode, isRewrite, reqTime }) {
if (pathname === "/favicon.ico") {
return;
}
this.logger.info(null, req({
url: pathname,
method,
statusCode,
isRewrite,
reqTime
}));
}
}