Unverified Commit cbc8319f authored by Hong Minhee's avatar Hong Minhee
Browse files

Add support for Nitro framework

parent c81bfe86
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ To be released.
    changes:

     -  Added support for [Express] framework.
     -  Added support for [Nitro] framework.
     -  Now a scaffold project uses a [x-forwarded-fetch] middleware to
        support `X-Forwarded-Proto` and `X-Forwarded-Host` headers.
     -  Now a scaffold project has hot reloading by default.
@@ -73,6 +74,7 @@ To be released.
[#69]: https://github.com/dahlia/fedify/issues/69
[#110]: https://github.com/dahlia/fedify/issues/110
[Express]: https://expressjs.com/
[Nitro]: https://nitro.unjs.io/


Version 0.12.2
+56 −2
Original line number Diff line number Diff line
@@ -74,10 +74,10 @@ const packageManagerAvailabilities: Record<PackageManager, boolean> = Object
    ),
  );

type WebFramework = "fresh" | "hono" | "express";
type WebFramework = "fresh" | "hono" | "express" | "nitro";

interface WebFrameworkInitializer {
  command?: [string, ...string[]];
  command?: [string, ...string[]] | [...string[], string];
  dependencies?: Record<string, string>;
  devDependencies?: Record<string, string>;
  federationFile: string;
@@ -336,6 +336,60 @@ To start the server, run the following command:
Then, try look up an actor from your server:

  ${colors.bold.green("fedify lookup http://localhost:8000/users/john")}
`,
    }),
  },
  nitro: {
    label: "Nitro",
    runtimes: ["bun", "node"],
    init: (_, runtime, pm) => ({
      command: [
        ...(runtime === "bun"
          ? ["bunx"]
          : pm === "npm"
          ? ["npx", "--yes"]
          : [pm, "dlx"]),
        "giget@latest",
        "nitro",
        ".",
        "--install",
      ],
      dependencies: {
        "@fedify/h3": "^0.1.0",
      },
      federationFile: "server/federation.ts",
      loggingFile: "server/logging.ts",
      files: {
        "server/middleware/federation.ts": `\
import { integrateFederation } from "@fedify/h3";
import federation from "../federation"

export default integrateFederation(
  federation,
  (event, request) => undefined,
);
`,
        "server/error.ts": `\
import { onError } from "@fedify/h3";

export default onError;
`,
        "nitro.config.ts": `\
//https://nitro.unjs.io/config
export default defineNitroConfig({
  srcDir: "server",
  errorHandler: "~/error"
});
`,
      },
      instruction: `
To start the server, run the following command:

  ${colors.bold.green(runtime === "bun" ? "bun dev" : `${pm} run dev`)}

Then, try look up an actor from your server:

  ${colors.bold.green("fedify lookup http://localhost:3000/users/john")}
`,
    }),
  },
+4 −2
Original line number Diff line number Diff line
@@ -90,8 +90,8 @@ project. It will ask you a few questions to set up the project:

 -  JavaScript runtime: [Deno], [Bun], or [Node.js]
 -  Package manager (if Node.js): [npm], [pnpm], or [Yarn]
 -  Web framework: Bare-bones, [Fresh] (if Deno), [Hono], or
    [Express] (unless Deno)
 -  Web framework: Bare-bones, [Fresh] (if Deno), [Hono], [Express] (unless
    Deno), or [Nitro] (unless Deno)
 -  Key-value store: In-memory, [Redis], or [Deno KV] (if Deno)
 -  Message queue: In-memory, [Redis], or [Deno KV] (if Deno)

@@ -104,6 +104,7 @@ interactive prompts:
[Fresh]: https://fresh.deno.dev/
[Hono]: https://hono.dev/
[Express]: https://expressjs.com/
[Nitro]: https://nitro.unjs.io/
[Redis]: https://redis.io/
[Deno KV]: https://deno.com/kv

@@ -136,6 +137,7 @@ the `-w`/`--web-framework` option. The available options are:
 -  `fresh`: [Fresh] (if Deno)
 -  `hono`: [Hono]
 -  `express`: [Express] (unless Deno)
 -  `nitro`: [Nitro] (unless Deno)

If it's omitted, no web framework will be integrated.