Loading cli/init.ts +65 −1 Original line number Diff line number Diff line Loading @@ -74,11 +74,12 @@ const packageManagerAvailabilities: Record<PackageManager, boolean> = Object ), ); type WebFramework = "fresh" | "hono"; type WebFramework = "fresh" | "hono" | "express"; interface WebFrameworkInitializer { command?: [string, ...string[]]; dependencies?: Record<string, string>; devDependencies?: Record<string, string>; federationFile: string; loggingFile: string; files?: Record<string, string>; Loading Loading @@ -271,6 +272,67 @@ 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")} `, }), }, express: { label: "Express", runtimes: ["bun", "node"], init: (projectName, runtime, pm) => ({ dependencies: { express: "^4.19.2", "@fedify/express": "^0.1.3", ...(runtime === "node" ? { tsx: "^4.16.2" } : {}), }, devDependencies: { "@types/express": "^4.17.21", }, federationFile: "src/federation.ts", loggingFile: "src/logging.ts", files: { "src/app.ts": `\ import express from "express"; import { integrateFederation } from "@fedify/express"; import { getLogger } from "@logtape/logtape"; import federation from "./federation"; const logger = getLogger(${JSON.stringify(projectName)}); export const app = express(); app.set("trust proxy", true); app.use(integrateFederation(federation, (req) => undefined)); app.get("/", (req, res) => res.send("Hello, Fedify!")); export default app; `, "src/index.ts": `\ import app from "./app"; import "./logging"; app.listen(8000, () => { console.log("Server started at http://localhost:8000"); }); `, }, tasks: { "dev": runtime === "bun" ? "bun run --hot ./src/index.ts" : "tsx watch ./src/index.ts", "prod": runtime === "bun" ? "bun run ./src/index.ts" : "node --import tsx ./src/index.ts", }, 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:8000/users/john")} Loading Loading @@ -764,6 +826,7 @@ await configure({ if (runtime !== "deno") { const devDependencies: Record<string, string> = { "@biomejs/biome": "^1.8.3", ...initializer.devDependencies, }; await addDependencies( runtime, Loading Loading @@ -1052,6 +1115,7 @@ async function getLatestFedifyVersion(version: string): Promise<string> { if (v === version) return version; else if (result.versions[v].yanked) continue; const semVer = parse(v); if (semVer.prerelease != null && semVer.prerelease.length > 0) continue; if (greaterThan(semVer, maxVersion)) maxVersion = semVer; } return format(maxVersion); Loading docs/cli.md +4 −1 Original line number Diff line number Diff line Loading @@ -90,7 +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), or [Hono] - Web framework: Bare-bones, [Fresh] (if Deno), [Hono], or [Express] (unless Deno) - Key-value store: In-memory, [Redis], or [Deno KV] (if Deno) - Message queue: In-memory, [Redis], or [Deno KV] (if Deno) Loading @@ -102,6 +103,7 @@ interactive prompts: [Yarn]: https://yarnpkg.com/ [Fresh]: https://fresh.deno.dev/ [Hono]: https://hono.dev/ [Express]: https://expressjs.com/ [Redis]: https://redis.io/ [Deno KV]: https://deno.com/kv Loading Loading @@ -133,6 +135,7 @@ the `-w`/`--web-framework` option. The available options are: - `fresh`: [Fresh] (if Deno) - `hono`: [Hono] - `express`: [Express] (unless Deno) If it's omitted, no web framework will be integrated. Loading docs/manual/integration.md +27 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,33 @@ Fedify is designed to be used together with web frameworks. This document explains how to integrate Fedify with web frameworks. Express ------- [Express] is a fast, unopinionated, minimalist web framework for Node.js. The [@fedify/express] package provides a middleware to integrate Fedify with Express: ~~~~ typescript import express from "express"; import { integrateFederation } from "@fedify/express"; import { createFederation } from "@fedify/fedify"; export const federation = createFederation<string>({ // Omitted for brevity; see the related section for details. }); export const app = express(); app.set("trust proxy", true); app.use(integrateFederation(federation, (req) => "context data goes here")); // [!code highlight] ~~~~ [Express]: https://expressjs.com/ [@fedify/express]: https://github.com/dahlia/fedify-express Hono ---- Loading Loading
cli/init.ts +65 −1 Original line number Diff line number Diff line Loading @@ -74,11 +74,12 @@ const packageManagerAvailabilities: Record<PackageManager, boolean> = Object ), ); type WebFramework = "fresh" | "hono"; type WebFramework = "fresh" | "hono" | "express"; interface WebFrameworkInitializer { command?: [string, ...string[]]; dependencies?: Record<string, string>; devDependencies?: Record<string, string>; federationFile: string; loggingFile: string; files?: Record<string, string>; Loading Loading @@ -271,6 +272,67 @@ 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")} `, }), }, express: { label: "Express", runtimes: ["bun", "node"], init: (projectName, runtime, pm) => ({ dependencies: { express: "^4.19.2", "@fedify/express": "^0.1.3", ...(runtime === "node" ? { tsx: "^4.16.2" } : {}), }, devDependencies: { "@types/express": "^4.17.21", }, federationFile: "src/federation.ts", loggingFile: "src/logging.ts", files: { "src/app.ts": `\ import express from "express"; import { integrateFederation } from "@fedify/express"; import { getLogger } from "@logtape/logtape"; import federation from "./federation"; const logger = getLogger(${JSON.stringify(projectName)}); export const app = express(); app.set("trust proxy", true); app.use(integrateFederation(federation, (req) => undefined)); app.get("/", (req, res) => res.send("Hello, Fedify!")); export default app; `, "src/index.ts": `\ import app from "./app"; import "./logging"; app.listen(8000, () => { console.log("Server started at http://localhost:8000"); }); `, }, tasks: { "dev": runtime === "bun" ? "bun run --hot ./src/index.ts" : "tsx watch ./src/index.ts", "prod": runtime === "bun" ? "bun run ./src/index.ts" : "node --import tsx ./src/index.ts", }, 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:8000/users/john")} Loading Loading @@ -764,6 +826,7 @@ await configure({ if (runtime !== "deno") { const devDependencies: Record<string, string> = { "@biomejs/biome": "^1.8.3", ...initializer.devDependencies, }; await addDependencies( runtime, Loading Loading @@ -1052,6 +1115,7 @@ async function getLatestFedifyVersion(version: string): Promise<string> { if (v === version) return version; else if (result.versions[v].yanked) continue; const semVer = parse(v); if (semVer.prerelease != null && semVer.prerelease.length > 0) continue; if (greaterThan(semVer, maxVersion)) maxVersion = semVer; } return format(maxVersion); Loading
docs/cli.md +4 −1 Original line number Diff line number Diff line Loading @@ -90,7 +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), or [Hono] - Web framework: Bare-bones, [Fresh] (if Deno), [Hono], or [Express] (unless Deno) - Key-value store: In-memory, [Redis], or [Deno KV] (if Deno) - Message queue: In-memory, [Redis], or [Deno KV] (if Deno) Loading @@ -102,6 +103,7 @@ interactive prompts: [Yarn]: https://yarnpkg.com/ [Fresh]: https://fresh.deno.dev/ [Hono]: https://hono.dev/ [Express]: https://expressjs.com/ [Redis]: https://redis.io/ [Deno KV]: https://deno.com/kv Loading Loading @@ -133,6 +135,7 @@ the `-w`/`--web-framework` option. The available options are: - `fresh`: [Fresh] (if Deno) - `hono`: [Hono] - `express`: [Express] (unless Deno) If it's omitted, no web framework will be integrated. Loading
docs/manual/integration.md +27 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,33 @@ Fedify is designed to be used together with web frameworks. This document explains how to integrate Fedify with web frameworks. Express ------- [Express] is a fast, unopinionated, minimalist web framework for Node.js. The [@fedify/express] package provides a middleware to integrate Fedify with Express: ~~~~ typescript import express from "express"; import { integrateFederation } from "@fedify/express"; import { createFederation } from "@fedify/fedify"; export const federation = createFederation<string>({ // Omitted for brevity; see the related section for details. }); export const app = express(); app.set("trust proxy", true); app.use(integrateFederation(federation, (req) => "context data goes here")); // [!code highlight] ~~~~ [Express]: https://expressjs.com/ [@fedify/express]: https://github.com/dahlia/fedify-express Hono ---- Loading