feat: support async route components (#1388)
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"lock": false,
|
||||
"tasks": {
|
||||
"start": "deno run -A --watch=static/,routes/ dev.ts"
|
||||
},
|
||||
"imports": {
|
||||
"$fresh/": "../../",
|
||||
"twind": "https://esm.sh/twind@0.16.19",
|
||||
"twind/": "https://esm.sh/twind@0.16.19/",
|
||||
"preact": "https://esm.sh/preact@10.15.1",
|
||||
"preact/": "https://esm.sh/preact@10.15.1/",
|
||||
"preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.1.0",
|
||||
"@preact/signals": "https://esm.sh/*@preact/signals@1.1.3",
|
||||
"@preact/signals-core": "https://esm.sh/@preact/signals-core@1.2.3"
|
||||
},
|
||||
"compilerOptions": {
|
||||
"jsx": "react-jsx",
|
||||
"jsxImportSource": "preact"
|
||||
}
|
||||
}
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env -S deno run -A --watch=static/,routes/
|
||||
|
||||
import dev from "$fresh/dev.ts";
|
||||
|
||||
await dev(import.meta.url, "./main.ts");
|
||||
@@ -0,0 +1,30 @@
|
||||
// DO NOT EDIT. This file is generated by fresh.
|
||||
// This file SHOULD be checked into source version control.
|
||||
// This file is automatically updated during development when running `dev.ts`.
|
||||
|
||||
import * as $0 from "./routes/basic.tsx";
|
||||
import * as $1 from "./routes/context/[id].tsx";
|
||||
import * as $2 from "./routes/fail.tsx";
|
||||
import * as $3 from "./routes/index.tsx";
|
||||
import * as $4 from "./routes/island.tsx";
|
||||
import * as $5 from "./routes/response.tsx";
|
||||
import * as $6 from "./routes/twind.tsx";
|
||||
import * as $$0 from "./islands/FooIsland.tsx";
|
||||
|
||||
const manifest = {
|
||||
routes: {
|
||||
"./routes/basic.tsx": $0,
|
||||
"./routes/context/[id].tsx": $1,
|
||||
"./routes/fail.tsx": $2,
|
||||
"./routes/index.tsx": $3,
|
||||
"./routes/island.tsx": $4,
|
||||
"./routes/response.tsx": $5,
|
||||
"./routes/twind.tsx": $6,
|
||||
},
|
||||
islands: {
|
||||
"./islands/FooIsland.tsx": $$0,
|
||||
},
|
||||
baseUrl: import.meta.url,
|
||||
};
|
||||
|
||||
export default manifest;
|
||||
@@ -0,0 +1,13 @@
|
||||
import { useSignal } from "@preact/signals";
|
||||
|
||||
export default function FooIsland() {
|
||||
const sig = useSignal(0);
|
||||
return (
|
||||
<button
|
||||
onClick={() => sig.value += 1}
|
||||
class="bg-gray-200 py-2 px-4 rounded m-8"
|
||||
>
|
||||
update {sig}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference no-default-lib="true" />
|
||||
/// <reference lib="dom" />
|
||||
/// <reference lib="dom.asynciterable" />
|
||||
/// <reference lib="deno.ns" />
|
||||
|
||||
import { start } from "$fresh/server.ts";
|
||||
import twind from "$fresh/plugins/twind.ts";
|
||||
import manifest from "./fresh.gen.ts";
|
||||
|
||||
import twindConfig from "./twind.config.ts";
|
||||
await start(manifest, { plugins: [twind(twindConfig)] });
|
||||
@@ -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>;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import * as colors from "twind/colors";
|
||||
|
||||
export default {
|
||||
selfURL: import.meta.url,
|
||||
theme: {
|
||||
colors: {
|
||||
blue: colors.blue,
|
||||
black: colors.black,
|
||||
gray: colors.gray,
|
||||
green: colors.green,
|
||||
red: colors.red,
|
||||
white: colors.white,
|
||||
yellow: colors.yellow,
|
||||
transparent: "transparent",
|
||||
},
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user