feat: add plugin configResolved (#2055)

This commit is contained in:
Marvin Hagemeister
2023-11-21 15:39:17 +01:00
committed by GitHub
parent 0a85a1fe5f
commit daf15aee6f
15 changed files with 134 additions and 1 deletions
@@ -0,0 +1,13 @@
{
"lock": false,
"imports": {
"$fresh/": "../../",
"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.2.1"
},
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "preact"
}
}
+6
View File
@@ -0,0 +1,6 @@
#!/usr/bin/env -S deno run -A --watch=static/,routes/
import dev from "$fresh/dev.ts";
import config from "./fresh.config.ts";
await dev(import.meta.url, "./main.ts", config);
@@ -0,0 +1,28 @@
import { defineConfig } from "$fresh/src/server/defines.ts";
const delay = (ms: number) => new Promise((r) => setTimeout(r, ms));
let called = false;
export default defineConfig({
plugins: [
{
name: "a",
async configResolved() {
await delay(1);
called = true;
},
middlewares: [
{
path: "/",
middleware: {
handler: async (_req, ctx) => {
const res = await ctx.next();
res.headers.append("X-Plugin-A", String(called));
return res;
},
},
},
],
},
],
});
@@ -0,0 +1,17 @@
// 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 $index from "./routes/index.tsx";
import { Manifest } from "$fresh/server.ts";
const manifest = {
routes: {
"./routes/index.tsx": $index,
},
islands: {},
baseUrl: import.meta.url,
} satisfies Manifest;
export default manifest;
+11
View File
@@ -0,0 +1,11 @@
/// <reference no-default-lib="true" />
/// <reference lib="dom" />
/// <reference lib="dom.iterable" />
/// <reference lib="dom.asynciterable" />
/// <reference lib="deno.ns" />
import { start } from "$fresh/server.ts";
import manifest from "./fresh.gen.ts";
import config from "./fresh.config.ts";
await start(manifest, config);
@@ -0,0 +1,7 @@
export default function Home() {
return (
<div>
<h1>Hello World</h1>
</div>
);
}