feat: support async route components (#1388)
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
export default async function Home() {
|
||||
await new Promise((r) => setTimeout(r, 10));
|
||||
return <h1>it works</h1>;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { RouteContext } from "../../../../server.ts";
|
||||
import { delay } from "../../../deps.ts";
|
||||
|
||||
export default async function Foo(_req: Request, context: RouteContext) {
|
||||
await delay(1);
|
||||
const value = JSON.stringify(context, (_key, value) => {
|
||||
if (typeof value === "function") return value.constructor.name;
|
||||
return value;
|
||||
}, 2);
|
||||
|
||||
return new Response(value, {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { RouteContext } from "$fresh/server.ts";
|
||||
|
||||
// deno-lint-ignore require-await
|
||||
export default async function Home(_req: Request, ctx: RouteContext) {
|
||||
return ctx.renderNotFound();
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import * as path from "https://deno.land/std@0.192.0/path/mod.ts";
|
||||
|
||||
const __dirname = path.dirname(path.fromFileUrl(import.meta.url));
|
||||
|
||||
const links: string[] = [];
|
||||
for (const file of Deno.readDirSync(__dirname)) {
|
||||
if (file.name.startsWith("index")) continue;
|
||||
const name = path.basename(file.name, path.extname(file.name));
|
||||
links.push(name);
|
||||
}
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<div class="mx-auto max-w-md">
|
||||
<h1 class="text-3xl font-bold my-8">Tests</h1>
|
||||
<ul class="pl-4">
|
||||
{links.map((link) => {
|
||||
return (
|
||||
<li key={link} class="list-disc">
|
||||
<a href={`/${link}`} class="underline">{link}</a>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import FooIsland from "../islands/FooIsland.tsx";
|
||||
|
||||
export default async function Island() {
|
||||
await new Promise((r) => setTimeout(r, 10));
|
||||
return <FooIsland />;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { delay } from "../../deps.ts";
|
||||
|
||||
export default async function Foo() {
|
||||
await delay(1);
|
||||
return new Response("it works", { status: 200 });
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
export default async function Twind() {
|
||||
await new Promise((r) => setTimeout(r, 10));
|
||||
return <h1 class="text-3xl text-red-600 font-bold">it works</h1>;
|
||||
}
|
||||
Reference in New Issue
Block a user