feat(views): zero-config static directory serving

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-07-10 14:42:20 -05:00
1 parent b8ebb9d04b
commit ad3a06f057
5 files changed
+130 -1

No files matched your search

+12
View File
@@ -69,6 +69,18 @@ export async function handle(
const matched = matchRoute(routes, req.method, path);
if (!matched) {
if ((req.method === 'GET' || req.method === 'HEAD') && opts?.static) {
const hit = await opts.static(path);
if (hit) {
const body = req.method === 'HEAD' ? '' : hit.body;
return {
injected,
outcome: { kind: 'buffered', status: 200, headers: { 'content-type': hit.contentType }, body },
};
}
}
// Path matches a route under a different method → 405 with Allow; otherwise 404.
const allow = allowedMethods(routes, path);
const err = allow.length ? new HttpError(405, 'Method Not Allowed') : new NotFound('Not Found');
+2
View File
@@ -4,6 +4,7 @@ import type { PipelineResult } from '../pipeline';
import type { ErrorRenderer } from '../transformers';
import type { TlsOptions, SecurityOptions, CorsOptions } from '../security';
import type { WsRequest } from './ws-core';
import type { StaticResolver } from '../views';
/** Per-request size and timeout ceilings applied by the server. */
export interface RequestLimits {
@@ -24,6 +25,7 @@ export interface HttpOptions {
cors?: CorsOptions;
bodyDuplicates?: 'array' | 'last';
onError?: ErrorRenderer;
static?: StaticResolver;
}
/** Handler for a matched HTTP route; receives a normalized request and resolves to a pipeline result. */