|
| 1 | +<!-- deno-fmt-ignore-file --> |
| 2 | + |
| 3 | +@fedify/nuxt: Integrate Fedify with Nuxt |
| 4 | +======================================== |
| 5 | + |
| 6 | +[![JSR][JSR badge]][JSR] |
| 7 | +[![npm][npm badge]][npm] |
| 8 | +[![Matrix][Matrix badge]][Matrix] |
| 9 | +[![Follow @fedify@hollo.social][@fedify@hollo.social badge]][@fedify@hollo.social] |
| 10 | + |
| 11 | +This package provides a simple way to integrate [Fedify] with [Nuxt]. |
| 12 | + |
| 13 | +Supported framework versions: |
| 14 | + |
| 15 | + - Nuxt 4.x |
| 16 | + - Nitro 2.x (Nuxt 4 runtime) |
| 17 | + |
| 18 | +[JSR badge]: https://jsr.io/badges/@fedify/nuxt |
| 19 | +[JSR]: https://jsr.io/@fedify/nuxt |
| 20 | +[npm badge]: https://img.shields.io/npm/v/@fedify/nuxt?logo=npm |
| 21 | +[npm]: https://www.npmjs.com/package/@fedify/nuxt |
| 22 | +[Matrix badge]: https://img.shields.io/matrix/fedify%3Amatrix.org |
| 23 | +[Matrix]: https://matrix.to/#/#fedify:matrix.org |
| 24 | +[@fedify@hollo.social badge]: https://fedi-badge.deno.dev/@fedify@hollo.social/followers.svg |
| 25 | +[@fedify@hollo.social]: https://hollo.social/@fedify |
| 26 | +[Fedify]: https://fedify.dev/ |
| 27 | +[Nuxt]: https://nuxt.com/ |
| 28 | + |
| 29 | + |
| 30 | +Installation |
| 31 | +------------ |
| 32 | + |
| 33 | +~~~~ bash |
| 34 | +deno add jsr:@fedify/nuxt |
| 35 | +# or |
| 36 | +npm add @fedify/nuxt |
| 37 | +# or |
| 38 | +pnpm add @fedify/nuxt |
| 39 | +# or |
| 40 | +yarn add @fedify/nuxt |
| 41 | +# or |
| 42 | +bun add @fedify/nuxt |
| 43 | +~~~~ |
| 44 | + |
| 45 | + |
| 46 | +Usage |
| 47 | +----- |
| 48 | + |
| 49 | +Create your `Federation` instance in *server/federation.ts*: |
| 50 | + |
| 51 | +~~~~ typescript |
| 52 | +import { createFederation, MemoryKvStore } from "@fedify/fedify"; |
| 53 | + |
| 54 | +const federation = createFederation({ |
| 55 | + kv: new MemoryKvStore(), |
| 56 | +}); |
| 57 | + |
| 58 | +// ... configure your federation ... |
| 59 | + |
| 60 | +export default federation; |
| 61 | +~~~~ |
| 62 | + |
| 63 | +Then enable the Nuxt module in *nuxt.config.ts*: |
| 64 | + |
| 65 | +~~~~ typescript |
| 66 | +export default defineNuxtConfig({ |
| 67 | + modules: ["@fedify/nuxt"], |
| 68 | +}); |
| 69 | +~~~~ |
| 70 | + |
| 71 | +By default, `@fedify/nuxt` loads your Federation instance from |
| 72 | +`~/server/federation`. |
| 73 | + |
| 74 | +If your project uses a different file path or context data factory, |
| 75 | +configure the module options: |
| 76 | + |
| 77 | +~~~~ typescript |
| 78 | +export default defineNuxtConfig({ |
| 79 | + modules: ["@fedify/nuxt"], |
| 80 | + fedify: { |
| 81 | + federationModule: "~/server/federation", |
| 82 | + contextDataFactoryModule: "~/server/fedify-context", |
| 83 | + }, |
| 84 | +}); |
| 85 | +~~~~ |
| 86 | + |
| 87 | +The context data factory module should export either: |
| 88 | + |
| 89 | + - default function, or |
| 90 | + - `contextDataFactory` named export |
| 91 | + |
| 92 | +with this signature: |
| 93 | + |
| 94 | +~~~~ typescript |
| 95 | +import type { ContextDataFactory } from "@fedify/nuxt"; |
| 96 | + |
| 97 | +const contextDataFactory: ContextDataFactory<unknown> = async (event, request) => { |
| 98 | + return { |
| 99 | + ip: event.node.req.socket.remoteAddress, |
| 100 | + method: request.method, |
| 101 | + }; |
| 102 | +}; |
| 103 | + |
| 104 | +export default contextDataFactory; |
| 105 | +~~~~ |
0 commit comments