@fedify/nuxt 2.2.0-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +105 -0
- package/dist/mod.cjs +68 -0
- package/dist/mod.d.cts +56828 -0
- package/dist/mod.d.ts +56828 -0
- package/dist/mod.js +68 -0
- package/package.json +71 -0
- package/src/runtime/server/lib.ts +4 -0
- package/src/runtime/server/logic.test.ts +50 -0
- package/src/runtime/server/logic.ts +60 -0
- package/src/runtime/server/middleware.ts +44 -0
- package/src/runtime/server/plugin.test.ts +118 -0
- package/src/runtime/server/plugin.ts +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright 2024–2026 Hong Minhee
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
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
|
+
~~~~
|
package/dist/mod.cjs
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
let _nuxt_kit = require("@nuxt/kit");
|
|
2
|
+
let node_path = require("node:path");
|
|
3
|
+
//#region src/module.ts
|
|
4
|
+
function resolveModulePath(modulePath, aliases, rootDir) {
|
|
5
|
+
const resolved = (0, _nuxt_kit.resolveAlias)(modulePath, aliases);
|
|
6
|
+
if ((0, node_path.isAbsolute)(resolved)) return resolved;
|
|
7
|
+
if (resolved.startsWith("./") || resolved.startsWith("../")) return (0, node_path.resolve)(rootDir, resolved);
|
|
8
|
+
return resolved;
|
|
9
|
+
}
|
|
10
|
+
function buildContextFactoryResolver(contextDataFactoryModule) {
|
|
11
|
+
if (contextDataFactoryModule == null) return "const contextDataFactory = undefined;";
|
|
12
|
+
return `
|
|
13
|
+
const contextDataFactory =
|
|
14
|
+
contextFactoryModule.default ??
|
|
15
|
+
contextFactoryModule.contextDataFactory;
|
|
16
|
+
if (contextDataFactory == null) {
|
|
17
|
+
throw new TypeError(
|
|
18
|
+
\'@fedify/nuxt: contextDataFactoryModule must export a function as "default" or named "contextDataFactory", but neither was found.\'
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
if (typeof contextDataFactory !== 'function') {
|
|
22
|
+
throw new TypeError(
|
|
23
|
+
\'@fedify/nuxt: contextDataFactoryModule must export a function as "default" or named "contextDataFactory".\'
|
|
24
|
+
);
|
|
25
|
+
}`;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Nuxt module to integrate Fedify with Nuxt/Nitro request handling.
|
|
29
|
+
*/
|
|
30
|
+
const fedifyNuxtModule = (0, _nuxt_kit.defineNuxtModule)({
|
|
31
|
+
meta: {
|
|
32
|
+
name: "@fedify/nuxt",
|
|
33
|
+
configKey: "fedify"
|
|
34
|
+
},
|
|
35
|
+
defaults: {
|
|
36
|
+
federationModule: "#server/federation",
|
|
37
|
+
contextDataFactoryModule: void 0
|
|
38
|
+
},
|
|
39
|
+
setup(options, nuxt) {
|
|
40
|
+
const resolver = (0, _nuxt_kit.createResolver)(require("url").pathToFileURL(__filename).href);
|
|
41
|
+
const rootDir = nuxt.options.rootDir;
|
|
42
|
+
const federationModule = resolveModulePath(options.federationModule, nuxt.options.alias, rootDir);
|
|
43
|
+
const contextDataFactoryModule = options.contextDataFactoryModule == null ? void 0 : resolveModulePath(options.contextDataFactoryModule, nuxt.options.alias, rootDir);
|
|
44
|
+
const middlewareFilename = "fedify-nuxt-options.mjs";
|
|
45
|
+
(0, _nuxt_kit.addServerTemplate)({
|
|
46
|
+
filename: middlewareFilename,
|
|
47
|
+
getContents: () => {
|
|
48
|
+
const imports = [`import * as federationModule from ${JSON.stringify(federationModule)};`, `import { createFedifyMiddleware } from ${JSON.stringify(resolver.resolve("../src/runtime/server/middleware.ts"))};`];
|
|
49
|
+
if (contextDataFactoryModule != null) imports.push(`import * as contextFactoryModule from ${JSON.stringify(contextDataFactoryModule)};`);
|
|
50
|
+
return [
|
|
51
|
+
...imports,
|
|
52
|
+
"const federation = federationModule.default ?? federationModule.federation;",
|
|
53
|
+
buildContextFactoryResolver(contextDataFactoryModule ?? null),
|
|
54
|
+
"export default createFedifyMiddleware(federation, contextDataFactory);",
|
|
55
|
+
""
|
|
56
|
+
].join("\n");
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
(0, _nuxt_kit.addServerHandler)({
|
|
60
|
+
route: "",
|
|
61
|
+
middleware: true,
|
|
62
|
+
handler: middlewareFilename
|
|
63
|
+
});
|
|
64
|
+
(0, _nuxt_kit.addServerPlugin)(resolver.resolve("../src/runtime/server/plugin.ts"));
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
//#endregion
|
|
68
|
+
module.exports = fedifyNuxtModule;
|