Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlia committed Jul 21, 2024
1 parent a4e5c52 commit e2b9f0c
Show file tree
Hide file tree
Showing 4 changed files with 260 additions and 104 deletions.
9 changes: 5 additions & 4 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default defineConfig({
link: "https://dash.deno.com/playground/fedify-demo",
},
{ text: "Installation", link: "/install.md" },
{ text: "Tutorial", link: "/tutorial.md" },
{ text: "In-depth tutorial", link: "/tutorial.md" },
{
text: "CLI toolchain",
link: "/cli.md",
Expand Down Expand Up @@ -127,7 +127,8 @@ export default defineConfig({
},
{
icon: {
svg: '<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>ActivityPub</title><path d="M10.91 4.442L0 10.74v2.52L8.727 8.22v10.077l2.182 1.26zM6.545 12l-4.364 2.52 4.364 2.518zm6.545-2.52L17.455 12l-4.364 2.52zm0-5.038L24 10.74v2.52l-10.91 6.298v-2.52L21.819 12 13.091 6.96z"/></svg>',
svg:
'<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>ActivityPub</title><path d="M10.91 4.442L0 10.74v2.52L8.727 8.22v10.077l2.182 1.26zM6.545 12l-4.364 2.52 4.364 2.518zm6.545-2.52L17.455 12l-4.364 2.52zm0-5.038L24 10.74v2.52l-10.91 6.298v-2.52L21.819 12 13.091 6.96z"/></svg>',
},
link: "https://hollo.social/@fedify",
ariaLabel: "Hollo (ActivityPub)",
Expand Down Expand Up @@ -181,8 +182,8 @@ export default defineConfig({
"meta",
{
name: "fediverse:creator",
content: "@fedify@hollo.social"
}
content: "@fedify@hollo.social",
},
],
...plausibleScript,
],
Expand Down
90 changes: 68 additions & 22 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,77 @@ prev:
text: What is Fedify?
link: ./intro.md
next:
text: Tutorial
text: In-depth tutorial
link: ./tutorial.md
---
Installation
============

Fedify is available on [JSR] for [Deno] and on [npm] for [Node.js] and [Bun].

> [!TIP]
> We recommend using Deno or Bun (which are TypeScript-first) for the best
> experience, but you can use Node.js if you prefer.
Quick start
-----------

The easiest way to start a new Fedify project is to use the `fedify init`
command. It creates a new directory with a minimal Fedify project template.

### CLI toolchain

First of all, you need to have the `fedify` command, the Fedify CLI toolchain,
installed on your system. If you haven't installed it yet, please follow the
following instructions:

::: code-group

~~~~ sh [Node.js]
npm install -g @fedify/cli
~~~~

~~~~ sh [Bun]
bun install -g @fedify/cli
~~~~

~~~~ sh [Deno]
deno install -A --unstable-fs --unstable-kv --unstable-temporal -n fedify jsr:@fedify/cli
~~~~

:::

There are other ways to install the `fedify` command. Please refer to the
[*Installation* section](./cli.md#installation) in the *CLI toolchain* docs.

### Project setup

After installing the `fedify` command, you can create a new Fedify project by
running the following command:

~~~~ sh
fedify init your-project-dir
~~~~

The above command will start a wizard to guide you through the project setup.
You can choose the JavaScript runtime, the package manager, and the web
framework you want to integrate Fedify with, and so on. After the wizard
finishes, you will have a new Fedify project in the *your-project-dir*
directory.

For more information about the `fedify init` command, please refer to the
[*`fedify init`* section](./cli.md#fedify-init-initializing-a-fedify-project)
in the *CLI toolchain* docs.


Manual installation
-------------------

Fedify is available on [JSR] for [Deno] and on [npm] for [Bun] and [Node.js].

[JSR]: https://jsr.io/@fedify/fedify
[Deno]: https://deno.com/
[npm]: https://www.npmjs.com/package/@fedify/fedify
[Node.js]: https://nodejs.org/
[Bun]: https://bun.sh/
[Node.js]: https://nodejs.org/


Deno
----
### Deno

[Deno] is the primary runtime for Fedify. As a prerequisite, you need to have
Deno 1.41.0 or later installed on your system. Then you can install Fedify
Expand All @@ -35,7 +85,7 @@ deno add @fedify/fedify
~~~~

Since Fedify requires [`Temporal`] API, which is an unstable feature in Deno as
of May 2024, you need to add the `"temporal"` to the `"unstable"` field of
of July 2024, you need to add the `"temporal"` to the `"unstable"` field of
the *deno.json* file:

~~~~ json{5}
Expand All @@ -49,9 +99,16 @@ the *deno.json* file:

[`Temporal`]: https://tc39.es/proposal-temporal/docs/

### Bun

Fedify can also be used in Bun. You can install it via the following
command:

~~~~ sh
bun add @fedify/fedify
~~~~

Node.js
-------
### Node.js

Fedify can also be used in Node.js. As a prerequisite, you need to have Node.js
20.0.0 or later installed on your system. Then you can install Fedify via
Expand All @@ -72,14 +129,3 @@ Fedify is an ESM-only package, so you need to add `"type": "module"` to the
}
}
~~~~


Bun
---

Fedify can also be used in Bun. You can install it via the following
command:

~~~~ sh
bun add @fedify/fedify
~~~~
77 changes: 77 additions & 0 deletions docs/manual/federation.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,83 @@ same path.
Turned off by default.


The `~Federation.fetch()` API
-----------------------------

*This API is available since Fedify 0.6.0.*

The `Federation` object provides the `~Federation.fetch()` method to handle
incoming HTTP requests. The `~Federation.fetch()` method takes an incoming
[`Request`] and returns a [`Response`].

Actually, this interface is de facto standard in the server-side JavaScript
world, and it is inspired by the [`window.fetch()`] method in the browser
environment.

Therefore, you can pass it to the [`Deno.serve()`] function in [Deno], and
the [`Bun.serve()`] function in [Bun]:

::: code-group

~~~~ typescript [Deno]
Deno.serve(
(request) => federation.fetch(request, { contextData: undefined })
);
~~~~

~~~~ typescript [Bun]
Bun.serve({
fetch: (request) => federation.fetch(request, { contextData: undefined }),
})
~~~~

:::

However, in case of [Node.js], it has no built-in server API that takes
`fetch()` callback function like Deno or Bun. Instead, you need to use
[@hono/node-server] package to adapt the `~Federation.fetch()` method to
the Node.js' HTTP server API:

::: code-group

~~~~ sh [Node.js]
npm add @hono/node-server
~~~~

:::

And then, you can use the [`serve()`] function from the package:

::: code-group

~~~~ typescript [Node.js]
import { serve } from "@hono/node-server";

serve({
fetch: (request) => federation.fetch(request, { contextData: undefined }),
})
~~~~

:::

> [!NOTE]
>
> Although a `Federation` object can be directly passed to the HTTP server
> APIs, you would usually integrate it with a web framework. For details,
> see the [*Integration* section](./integration.md).
[`Request`]: https://developer.mozilla.org/en-US/docs/Web/API/Request
[`Response`]: https://developer.mozilla.org/en-US/docs/Web/API/Response
[`window.fetch()`]: https://developer.mozilla.org/en-US/docs/Web/API/Window/fetch
[`Deno.serve()`]: https://docs.deno.com/api/deno/~/Deno.serve
[Deno]: http://deno.com/
[`Bun.serve()`]: https://bun.sh/docs/api/http#bun-serve
[Bun]: https://bun.sh/
[Node.js]: https://nodejs.org/
[@hono/node-server]: https://github.com/honojs/node-server
[`serve()`]: https://github.com/honojs/node-server?tab=readme-ov-file#usage


How the `Federation` object recognizes the domain name
------------------------------------------------------

Expand Down
Loading

0 comments on commit e2b9f0c

Please sign in to comment.