feat: expose layouts and pages on App (#3086)
This PR extracts the functionality from the `fs_routes` plugin and exposes it onto `App`. These are the new APIs: - `app.layout(pattern, route)` - `app.onError(pattern, route)` - `app.notFound(pattern, route)` - `app.route(pattern, route)` This also removes the need for `.use(staticFiles())`. This line can be safely removed. Fixes https://github.com/denoland/fresh/issues/3040 Fixes https://github.com/denoland/fresh/issues/3033 Fixes https://github.com/denoland/fresh/issues/2591 Fixes https://github.com/denoland/fresh/issues/950 Fixes https://github.com/denoland/fresh/issues/1918
This commit is contained in:
+12
-3
@@ -1,4 +1,4 @@
|
||||
import { FreshReqContext } from "./context.ts";
|
||||
import { Context } from "./context.ts";
|
||||
import type { FsAdapter } from "./fs.ts";
|
||||
import { type BuildCache, ProdBuildCache } from "./build_cache.ts";
|
||||
import type { ResolvedFreshConfig } from "./config.ts";
|
||||
@@ -45,6 +45,15 @@ export class FakeServer {
|
||||
const req = new Request(url, { method: "head" });
|
||||
return await this.handler(req, STUB);
|
||||
}
|
||||
async options(path: string): Promise<Response> {
|
||||
const url = this.toUrl(path);
|
||||
const req = new Request(url, { method: "options" });
|
||||
return await this.handler(req, STUB);
|
||||
}
|
||||
|
||||
async request(req: Request): Promise<Response> {
|
||||
return await this.handler(req, STUB);
|
||||
}
|
||||
|
||||
private toUrl(path: string) {
|
||||
return new URL(path, "http://localhost/");
|
||||
@@ -62,7 +71,7 @@ const DEFAULT_CONFIG: ResolvedFreshConfig = {
|
||||
};
|
||||
|
||||
export function serveMiddleware<T>(
|
||||
middleware: (ctx: FreshReqContext<T>) => Response | Promise<Response>,
|
||||
middleware: (ctx: Context<T>) => Response | Promise<Response>,
|
||||
options: {
|
||||
config?: ResolvedFreshConfig;
|
||||
buildCache?: BuildCache;
|
||||
@@ -76,7 +85,7 @@ export function serveMiddleware<T>(
|
||||
const buildCache = options.buildCache ??
|
||||
new ProdBuildCache(config, new Map(), new Map(), true);
|
||||
|
||||
const ctx = new FreshReqContext<T>(
|
||||
const ctx = new Context<T>(
|
||||
req,
|
||||
new URL(req.url),
|
||||
DEFAULT_CONN_INFO,
|
||||
|
||||
Reference in New Issue
Block a user