### Install Example Dependencies Source: https://github.com/fedify-dev/fedify/blob/main/examples/elysia/README.md Navigate to the Elysia example directory and install its dependencies using pnpm. ```sh cd ../../examples/elysia pnpm install ``` -------------------------------- ### Run the example application Source: https://github.com/fedify-dev/fedify/blob/main/examples/nuxt/README.md Use this command to start the Fedify Nuxt integration example application. ```sh pnpm dev ``` -------------------------------- ### Install and Run Development Server Source: https://github.com/fedify-dev/fedify/blob/main/docs/README.md Commands to install dependencies and start the local development server for the Fedify documentation. ```bash pnpm install pnpm dev ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/fedify-dev/fedify/blob/main/docs/tutorial/astro-blog.md Navigate to the project directory and install all necessary dependencies using `bun install`. ```sh cd astro-blog bun install ``` -------------------------------- ### Start Elysia Server Source: https://github.com/fedify-dev/fedify/blob/main/examples/elysia/README.md Start the Elysia server using Bun to run the Fedify integration example. ```sh bun run start ``` -------------------------------- ### Install @fedify/fresh Source: https://github.com/fedify-dev/fedify/blob/main/docs/manual/integration.md Install the Fedify Fresh module for Deno. ```sh deno add jsr:@fedify/fresh ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/fedify-dev/fedify/blob/main/CONTRIBUTING.md Install Deno, Node.js, and Bun with the correct versions specified in mise.toml. This command should be run after installing mise. ```bash mise trust mise install ``` -------------------------------- ### Enable and Start Fedify Service Source: https://github.com/fedify-dev/fedify/blob/main/docs/manual/deploy.md Commands to enable the Fedify service to start on boot and to start it immediately. Also includes a command to follow the service logs. ```bash systemctl enable --now fedify.service journalctl -u fedify.service -f ``` -------------------------------- ### Install PostgresMessageQueue (Deno) Source: https://github.com/fedify-dev/fedify/blob/main/docs/manual/mq.md Install the @fedify/postgres package for Deno. ```bash deno add jsr:@fedify/postgres ``` -------------------------------- ### Install AmqpMessageQueue (Deno) Source: https://github.com/fedify-dev/fedify/blob/main/docs/manual/mq.md Install the @fedify/amqp package for Deno. ```bash deno add jsr:@fedify/amqp ``` -------------------------------- ### Install PostgresMessageQueue (Bun) Source: https://github.com/fedify-dev/fedify/blob/main/docs/manual/mq.md Install the @fedify/postgres package using Bun. ```bash bun add @fedify/postgres ``` -------------------------------- ### Install @fedify/webfinger with Bun Source: https://github.com/fedify-dev/fedify/blob/main/docs/manual/webfinger.md Install the WebFinger client package using Bun. ```bash bun add @fedify/webfinger ``` -------------------------------- ### Install AmqpMessageQueue (Bun) Source: https://github.com/fedify-dev/fedify/blob/main/docs/manual/mq.md Install the @fedify/amqp package using Bun. ```bash bun add @fedify/amqp ``` -------------------------------- ### Install @fedify/webfinger with Deno Source: https://github.com/fedify-dev/fedify/blob/main/docs/manual/webfinger.md Install the WebFinger client package using Deno. ```bash deno add jsr:@fedify/webfinger ``` -------------------------------- ### Install @fedify/solidstart Source: https://github.com/fedify-dev/fedify/blob/main/docs/manual/integration.md Install the Fedify SolidStart package using different package managers. ```sh deno add jsr:@fedify/solidstart ``` ```sh npm add @fedify/solidstart ``` ```sh pnpm add @fedify/solidstart ``` ```sh yarn add @fedify/solidstart ``` ```sh bun add @fedify/solidstart ``` -------------------------------- ### Install @fedify/testing with deno Source: https://github.com/fedify-dev/fedify/blob/main/packages/testing/README.md Use deno add to install the @fedify/testing package. ```bash deno add @fedify/testing ``` -------------------------------- ### Install x-forwarded-fetch for Bun Source: https://github.com/fedify-dev/fedify/blob/main/docs/manual/federation.md Install the x-forwarded-fetch package for Bun using bun add. ```sh bun add x-forwarded-fetch ``` -------------------------------- ### Build and Serve Documentation Source: https://github.com/fedify-dev/fedify/blob/main/CONTRIBUTING.md Build the project documentation and start a local development server to preview changes. Access the docs at http://localhost:5173/. ```bash mise run docs ``` -------------------------------- ### Example Deployment Commands Source: https://github.com/fedify-dev/fedify/blob/main/examples/sveltekit-sample/README.md A set of commands for building, previewing, and deploying the application. Includes instructions for production build and preview, with notes on platform-specific deployment. ```bash # Build for production pnpm build # Preview the build pnpm preview # Or deploy to your preferred platform # (Vercel, Netlify, Docker, etc.) ``` -------------------------------- ### Manually Start Message Queue (Node.js/Bun) Source: https://github.com/fedify-dev/fedify/blob/main/docs/manual/mq.md Configure Fedify to manually start the message queue by setting `manuallyStartQueue: true`. This example demonstrates starting the queue only in worker nodes using Node.js environment variables and signal handling. ```typescript import type { KvStore } from "@fedify/fedify"; // ---cut-before--- import { createFederation } from "@fedify/fedify"; import { RedisMessageQueue } from "@fedify/redis"; import Redis from "ioredis"; import process from "node:process"; const federation = createFederation({ queue: new RedisMessageQueue(() => new Redis()), manuallyStartQueue: true, // [!code highlight] // ... other options // ---cut-start--- kv: null as unknown as KvStore, // ---cut-end--- }); // Start the message queue manually only in worker nodes. // On non-worker nodes, the queue won't be started. if (process.env.NODE_TYPE === "worker") { const controller = new AbortController(); process.on("SIGINT", () => controller.abort()); ``` -------------------------------- ### Basic Server Setup (Deno) Source: https://github.com/fedify-dev/fedify/blob/main/docs/tutorial/basics.md Sets up a basic HTTP server using Deno's serve function that responds with 'Hello, world'. ```typescript Deno.serve(request => new Response("Hello, world", { headers: { "Content-Type": "text/plain" } }) ); ``` -------------------------------- ### Manually Start Message Queue (Deno) Source: https://github.com/fedify-dev/fedify/blob/main/docs/manual/mq.md Configure Fedify to manually start the message queue by setting `manuallyStartQueue: true`. This example shows how to start the queue only in worker nodes using Deno environment variables and signal handling. ```typescript import type { KvStore } from "@fedify/fedify"; // ---cut-before--- import { createFederation } from "@fedify/fedify"; import { RedisMessageQueue } from "@fedify/redis"; import Redis from "ioredis"; const federation = createFederation({ queue: new RedisMessageQueue(() => new Redis()), manuallyStartQueue: true, // [!code highlight] // ... other options // ---cut-start--- kv: null as unknown as KvStore, // ---cut-end--- }); // Start the message queue manually only in worker nodes. // On non-worker nodes, the queue won't be started. if (Deno.env.get("NODE_TYPE") === "worker") { const controller = new AbortController(); Deno.addSignalListener("SIGINT", () => controller.abort()); await federation.startQueue(undefined, { signal: controller.signal }); } ``` -------------------------------- ### Run All Example Tests Source: https://github.com/fedify-dev/fedify/blob/main/CONTRIBUTING.md Execute this command from the project root to run tests for all example projects. ```bash mise run test:examples ``` -------------------------------- ### Implement POST /setup Handler Source: https://github.com/fedify-dev/fedify/blob/main/docs/tutorial/microblog.md Implement the `POST /setup` handler to create a new user account. It checks for existing accounts, validates the username, and inserts the new user into the database. ```typescript import { Hono } from "hono"; const app = new Hono(); import Database from "better-sqlite3"; const db = new Database(""); interface User {} // ---cut-before--- app.post("/setup", async (c) => { // Check if an account already exists const user = db.prepare("SELECT * FROM users LIMIT 1").get(); if (user != null) return c.redirect("/"); const form = await c.req.formData(); const username = form.get("username"); if (typeof username !== "string" || !username.match(/^[a-z0-9_-]{1,50}$/)) { return c.redirect("/setup"); } db.prepare("INSERT INTO users (username) VALUES (?)").run(username); return c.redirect("/"); }); ``` -------------------------------- ### GET / Request Handler for Home Page Source: https://github.com/fedify-dev/fedify/blob/main/docs/tutorial/microblog.md Handles GET requests to the root path. It fetches user data and renders the Home component within a Layout. Redirects to setup if no user is found. ```tsx import { Hono } from "hono"; const app = new Hono(); import Database from "better-sqlite3"; const db = new Database(""); interface Actor {} interface User {} import type { FC } from "hono/jsx"; export const Layout: FC = (props) => ; export const Home: FC = () => <>; // ---cut-before--- app.get("/", (c) => { const user = db .prepare( ` SELECT users.*, actors.* FROM users JOIN actors ON users.id = actors.user_id LIMIT 1 `, ) .get(); if (user == null) return c.redirect("/setup"); return c.html( , ); }); ``` -------------------------------- ### Basic Server Setup (Bun) Source: https://github.com/fedify-dev/fedify/blob/main/docs/tutorial/basics.md Sets up a basic HTTP server using Bun's serve function, listening on port 8000 and responding with 'Hello, world'. ```typescript import "bun"; // ---cut-before--- Bun.serve({ port: 8000, fetch(request) { return new Response("Hello, world", { ``` -------------------------------- ### Add Account Existence Check to GET /setup Source: https://github.com/fedify-dev/fedify/blob/main/docs/tutorial/microblog.md Add code to the `GET /setup` handler to check if an account already exists before rendering the setup form. Redirects to the homepage if an account is found. ```tsx import { Hono } from "hono"; const app = new Hono(); import type { FC } from "hono/jsx"; export const Layout: FC = (props) => ; export const SetupForm: FC = () => <>; import Database from "better-sqlite3"; const db = new Database(""); interface User {} // ---cut-before--- app.get("/setup", (c) => { // Check if an account already exists const user = db.prepare("SELECT * FROM users LIMIT 1").get(); if (user != null) return c.redirect("/"); return c.html( , ); }); ``` -------------------------------- ### Initialize Astro Blog Project Source: https://github.com/fedify-dev/fedify/blob/main/docs/tutorial/astro-blog.md Use `fedify init` to create a new Astro blog project directory. This command prompts for configuration choices. ```sh fedify init astro-blog ``` -------------------------------- ### Clone Fedify SvelteKit Sample Repository Source: https://github.com/fedify-dev/fedify/blob/main/examples/sveltekit-sample/README.md Clone the repository to get started with the SvelteKit sample application. ```bash git clone https://github.com/fedify-dev/fedify.git cd fedify/examples/sveltekit-sample ``` -------------------------------- ### Implement Custom KvStore in TypeScript Source: https://github.com/fedify-dev/fedify/blob/main/docs/manual/kv.md Define a custom KvStore by implementing the KvStore interface. This example shows the basic structure required for get, set, delete, and list operations. ```typescript import { KvStore, KvKey, KvStoreSetOptions } from "@fedify/fedify"; class MyCustomKvStore implements KvStore { async get(key: KvKey): Promise { return undefined; } async set( key: KvKey, value: unknown, options?: KvStoreSetOptions ): Promise { } async delete(key: KvKey): Promise { } async *list(): AsyncIterable<{ key: KvKey; value: unknown }> { } } ``` -------------------------------- ### Configure Bun Adapter for Fedify Astro Integration Source: https://github.com/fedify-dev/fedify/blob/main/packages/astro/README.md For Bun users, install @nurodev/astro-bun and configure it as the Astro adapter. Use Bun to start Astro in development and run the generated server entry point after building. ```typescript import { defineConfig } from "astro/config"; import { fedifyIntegration } from "@fedify/astro"; import bun from "@nurodev/astro-bun"; export default defineConfig({ integrations: [fedifyIntegration()], output: "server", adapter: bun(), }); ``` ```json { "scripts": { "dev": "bunx --bun astro dev", "build": "bunx --bun astro build", "preview": "bun ./dist/server/entry.mjs" } } ``` -------------------------------- ### Create Project Directory and Add Fedify (Bun) Source: https://github.com/fedify-dev/fedify/blob/main/docs/tutorial/basics.md Initializes a new project directory and adds the Fedify and Deno KV packages for Bun. ```sh mkdir follow-server cd follow-server/ echo '{ "type": "module" }' > package.json bun add @fedify/fedify @deno/kv ``` -------------------------------- ### Deno ExecStart Configuration Source: https://github.com/fedify-dev/fedify/blob/main/docs/manual/deploy.md Example of how to configure the ExecStart line for Fedify when running with Deno, specifying necessary permissions. ```bash /usr/bin/deno serve --allow-net --allow-env --allow-read=/srv/fedify --allow-write=/var/lib/fedify /srv/fedify/index.ts ``` -------------------------------- ### Configure LogTape Logger Source: https://github.com/fedify-dev/fedify/blob/main/docs/manual/log.md Configure the LogTape logger in your app's entry point. This setup defines where logs go (sinks) and what gets logged (loggers and levels). Ensure to import necessary functions from `@logtape/logtape`. ```typescript import { AsyncLocalStorage } from "node:async_hooks"; import { configure, getConsoleSink } from "@logtape/logtape"; await configure({ sinks: { console: getConsoleSink() }, loggers: [ { category: "your-app", sinks: ["console"], lowestLevel: "debug" }, { category: "fedify", sinks: ["console"], lowestLevel: "error" }, ], contextLocalStorage: new AsyncLocalStorage(), }); ``` -------------------------------- ### Navigate to Fresh Example Directory Source: https://github.com/fedify-dev/fedify/blob/main/examples/fresh/README.md Change the current directory to the Fresh example folder within the Fedify repository. ```sh cd examples/fresh ``` -------------------------------- ### Install x-forwarded-fetch for Node.js Source: https://github.com/fedify-dev/fedify/blob/main/docs/manual/federation.md Install the x-forwarded-fetch package for Node.js using npm install. ```sh npm install x-forwarded-fetch ``` -------------------------------- ### Create Project Directory and Add Fedify (Deno) Source: https://github.com/fedify-dev/fedify/blob/main/docs/tutorial/basics.md Initializes a new project directory and adds the Fedify package for Deno. ```sh mkdir follow-server cd follow-server/ echo '{ "unstable": ["kv"] }' > deno.json deno add jsr:@fedify/fedify ``` -------------------------------- ### Configure Project with Fedify Init Prompts Source: https://github.com/fedify-dev/fedify/blob/main/docs/tutorial/astro-blog.md Select 'Astro', 'bun', 'in-process', and 'in-memory' during the `fedify init` prompts to configure the project for this tutorial. ```console ___ _____ _ _ __ /'_') | ___|__ __| (_)/ _|_ _ .-^^^-/ / | |_ / _ \/ _` | | |_| | | | __/ / | _| __/ (_| | | _| |_| | <__.|_|-|_| |_| \___|\__,_|_|_| \__, | |___/ ? Choose the web framework to use Bare-bones Hono Nitro Next.js ElysiaJS ❯ Astro Express ? Choose the package manager to use deno pnpm ❯ bun yarn npm ? Choose the message queue to use ❯ in-process redis postgres mysql amqp ? Choose the key-value store to use ❯ in-memory redis postgres mysql ``` -------------------------------- ### Start Only Inbox Queue Worker (Deno) Source: https://github.com/fedify-dev/fedify/blob/main/docs/manual/mq.md Demonstrates how to start only the inbox queue worker when manually starting task workers. Requires `manuallyStartQueue: true` in FederationOptions. ```typescript import type { KvStore } from "@fedify/fedify"; import { createFederation } from "@fedify/fedify"; import { RedisMessageQueue } from "@fedify/redis"; import Redis from "ioredis"; const federation = createFederation({ queue: new RedisMessageQueue(() => new Redis()), manuallyStartQueue: true, // [!code highlight] // ... other options // ---cut-start--- kv: null as unknown as KvStore, // ---cut-end--- }); // ---cut-before--- if (Deno.env.get("NODE_TYPE") === "worker") { const controller = new AbortController(); Deno.addSignalListener("SIGINT", () => controller.abort()); await federation.startQueue(undefined, { signal: controller.signal, queue: "inbox", // [!code highlight] }); } ``` -------------------------------- ### Install Dependencies Source: https://github.com/fedify-dev/fedify/blob/main/examples/next15-app-router/README.md Install project dependencies using pnpm. ```sh pnpm i ``` -------------------------------- ### Start Fresh Development Server Source: https://github.com/fedify-dev/fedify/blob/main/examples/fresh/README.md Run the development server for the Fresh application using the Deno task. ```sh deno task dev ``` -------------------------------- ### Preview Project Initialization Source: https://github.com/fedify-dev/fedify/blob/main/docs/cli.md Use the `--dry-run` option to preview files and configurations that would be created without actually making any changes to the filesystem. This is useful for reviewing the project structure before committing to initialization. ```sh fedify init my-fedify-project --dry-run ``` -------------------------------- ### Install @fedify/init for Deno, npm, pnpm, Yarn, or Bun Source: https://github.com/fedify-dev/fedify/blob/main/packages/init/README.md Install the @fedify/init package using the appropriate command for your package manager. ```sh deno add jsr:@fedify/init # Deno npm add @fedify/init # npm pnpm add @fedify/init # pnpm yarn add @fedify/init # Yarn bun add @fedify/init # Bun ``` -------------------------------- ### Initialize a new Fedify project Source: https://github.com/fedify-dev/fedify/blob/main/docs/install.md Create a new Fedify project directory with a minimal template using the Fedify CLI. ```sh fedify init your-project-dir ``` -------------------------------- ### Install sanitize-html Source: https://github.com/fedify-dev/fedify/blob/main/docs/tutorial/content-sharing.md Install the `sanitize-html` library and its types using npm. ```sh npm install sanitize-html npm install -D @types/sanitize-html ``` -------------------------------- ### Create Fedify project with Bun Source: https://github.com/fedify-dev/fedify/blob/main/docs/install.md Initialize a new Fedify project without globally installing the Fedify CLI, using Bun. ```sh bunx @fedify/create your-project-dir ``` -------------------------------- ### Install @fedify/testing with yarn Source: https://github.com/fedify-dev/fedify/blob/main/packages/testing/README.md Use yarn to install the @fedify/testing package. ```bash yarn add @fedify/testing ``` -------------------------------- ### Install OpenTelemetry SDK Packages Source: https://github.com/fedify-dev/fedify/blob/main/docs/manual/opentelemetry.md Install the OpenTelemetry SDK and OTLP trace exporter for Deno, Node.js, or Bun. ```sh deno add npm:@opentelemetry/sdk-node npm:@opentelemetry/exporter-trace-otlp-proto ``` ```sh npm add @opentelemetry/sdk-node @opentelemetry/exporter-trace-otlp-proto ``` ```sh bun add @opentelemetry/sdk-node @opentelemetry/exporter-trace-otlp-proto ``` -------------------------------- ### Setup and Build Fedify Packages Source: https://github.com/fedify-dev/fedify/blob/main/CONTRIBUTING.md After setting up the development environment, run this command to automatically handle code generation and build all packages. This is a prerequisite for coding or testing. ```bash mise run install # This runs codegen and builds all packages ``` -------------------------------- ### Install @fedify/testing with pnpm Source: https://github.com/fedify-dev/fedify/blob/main/packages/testing/README.md Use pnpm to install the @fedify/testing package. ```bash pnpm add @fedify/testing ``` -------------------------------- ### Install @fedify/testing with npm Source: https://github.com/fedify-dev/fedify/blob/main/packages/testing/README.md Use npm to install the @fedify/testing package. ```bash npm install @fedify/testing ``` -------------------------------- ### Navigate to Project Directory and List Files Source: https://github.com/fedify-dev/fedify/blob/main/docs/tutorial/content-sharing.md Change the current directory to the newly created project and list all its files and directories to explore the generated structure. ```sh cd content-sharing ls -a ``` -------------------------------- ### Run Specific Example Tests Source: https://github.com/fedify-dev/fedify/blob/main/CONTRIBUTING.md To test particular example projects, append their names as arguments to the test command. ```bash mise run test:examples astro sveltekit-sample ``` -------------------------------- ### Install Dependencies Source: https://github.com/fedify-dev/fedify/blob/main/examples/express/README.md Install the necessary project dependencies using pnpm. ```sh pnpm install ``` -------------------------------- ### Install AmqpMessageQueue (Yarn) Source: https://github.com/fedify-dev/fedify/blob/main/docs/manual/mq.md Install the @fedify/amqp package using Yarn. ```bash yarn add @fedify/amqp ``` -------------------------------- ### Install AmqpMessageQueue (pnpm) Source: https://github.com/fedify-dev/fedify/blob/main/docs/manual/mq.md Install the @fedify/amqp package using pnpm. ```bash pnpm add @fedify/amqp ``` -------------------------------- ### Test Init Command with Default Options Source: https://github.com/fedify-dev/fedify/blob/main/CONTRIBUTING.md Runs the 'fedify init' command with various default combinations of web frameworks, package managers, KvStore, and MessageQueue implementations. This task is for contributors only. ```bash mise test:init ```