-
-
Notifications
You must be signed in to change notification settings - Fork 96
Add @fedify/solidstart package for SolidStart integration #601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dodok8
wants to merge
10
commits into
fedify-dev:main
Choose a base branch
from
dodok8:solidstart
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+5,685
−292
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a99425b
Add example solidstart
dodok8 11151a4
Add @fedify/solidstart package for SolidStart integration
dodok8 c903270
Add SolidStart integration documentation and changelog entry
dodok8 423eb33
Fix elysia section
dodok8 de20f3c
Add SolidStart option to fedify init
dodok8 71e64ff
Format all file
dodok8 dc34482
Fix markdown formatting for hongdown
dodok8 baa43b0
Remove unnecessary async from callbacks
dodok8 dd3ecb1
Add explicit subpath imports for SolidStart in Deno init template
dodok8 dc1fb84
Refactor lookup test exclusion rules
dodok8 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| node_modules | ||
| dist | ||
| .output | ||
| .vinxi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { defineConfig } from "@solidjs/start/config"; | ||
|
|
||
| export default defineConfig({ | ||
| middleware: "src/middleware/index.ts", | ||
| server: { | ||
| preset: "node-server", | ||
| }, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "name": "solidstart-example", | ||
| "version": "0.0.1", | ||
| "private": true, | ||
| "type": "module", | ||
| "description": "Fedify app with SolidStart integration", | ||
| "scripts": { | ||
| "dev": "vinxi dev", | ||
| "build": "vinxi build", | ||
| "start": "vinxi start" | ||
| }, | ||
| "dependencies": { | ||
| "@fedify/fedify": "workspace:^", | ||
| "@fedify/solidstart": "workspace:^", | ||
| "@fedify/vocab": "workspace:^", | ||
| "@solidjs/router": "^0.15.4", | ||
| "@solidjs/start": "^1.3.2", | ||
| "solid-js": "^1.9.11", | ||
| "vinxi": "^0.5.11" | ||
| }, | ||
| "devDependencies": { | ||
| "typescript": "^5.5.4" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| body { | ||
| font-family: system-ui, -apple-system, sans-serif; | ||
| max-width: 800px; | ||
| margin: 0 auto; | ||
| padding: 2rem; | ||
| line-height: 1.6; | ||
| } | ||
|
|
||
| h1 { | ||
| border-bottom: 1px solid #ccc; | ||
| padding-bottom: 0.5rem; | ||
| } | ||
|
|
||
| .profile { | ||
| padding: 1rem; | ||
| border: 1px solid #ddd; | ||
| border-radius: 8px; | ||
| } | ||
|
|
||
| .profile h2 { | ||
| margin-top: 0; | ||
| } | ||
|
|
||
| .followers { | ||
| margin-top: 1rem; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { Router } from "@solidjs/router"; | ||
| import { FileRoutes } from "@solidjs/start/router"; | ||
| import { Suspense } from "solid-js"; | ||
| import "./app.css"; | ||
|
|
||
| export default function App() { | ||
| return ( | ||
| <Router root={(props) => <Suspense>{props.children}</Suspense>}> | ||
| <FileRoutes /> | ||
| </Router> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| // @refresh reload | ||
| import { mount, StartClient } from "@solidjs/start/client"; | ||
|
|
||
| mount(() => <StartClient />, document.getElementById("app")!); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // @refresh reload | ||
| import { createHandler, StartServer } from "@solidjs/start/server"; | ||
|
|
||
| export default createHandler(() => ( | ||
| <StartServer | ||
| document={({ assets, children, scripts }) => ( | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="utf-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
| {assets} | ||
| </head> | ||
| <body> | ||
| <div id="app">{children}</div> | ||
| {scripts} | ||
| </body> | ||
| </html> | ||
| )} | ||
| /> | ||
| )); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| import { | ||
| createFederation, | ||
| generateCryptoKeyPair, | ||
| MemoryKvStore, | ||
| } from "@fedify/fedify"; | ||
| import { | ||
| Accept, | ||
| Endpoints, | ||
| Follow, | ||
| Note, | ||
| Person, | ||
| type Recipient, | ||
| Undo, | ||
| } from "@fedify/vocab"; | ||
| import { keyPairsStore, relationStore } from "./store"; | ||
|
|
||
| const federation = createFederation<void>({ | ||
| kv: new MemoryKvStore(), | ||
| }); | ||
|
|
||
| const IDENTIFIER = "demo"; | ||
|
|
||
| federation.setNodeInfoDispatcher("/nodeinfo/2.1", (_ctx) => { | ||
| return { | ||
| software: { | ||
| name: "fedify-solidstart", | ||
| version: "0.0.1", | ||
| }, | ||
| protocols: ["activitypub"], | ||
| usage: { | ||
| users: { total: 1, activeHalfyear: 1, activeMonth: 1 }, | ||
| localPosts: 0, | ||
| localComments: 0, | ||
| }, | ||
| }; | ||
| }); | ||
|
|
||
| federation | ||
| .setActorDispatcher("/users/{identifier}", async (context, identifier) => { | ||
| if (identifier !== IDENTIFIER) { | ||
| return null; | ||
| } | ||
| const keyPairs = await context.getActorKeyPairs(identifier); | ||
| return new Person({ | ||
| id: context.getActorUri(identifier), | ||
| name: "Fedify Demo", | ||
| summary: "This is a Fedify Demo account on SolidStart.", | ||
| preferredUsername: identifier, | ||
| url: new URL("/", context.url), | ||
| inbox: context.getInboxUri(identifier), | ||
| endpoints: new Endpoints({ sharedInbox: context.getInboxUri() }), | ||
| publicKey: keyPairs[0].cryptographicKey, | ||
| assertionMethods: keyPairs.map((keyPair) => keyPair.multikey), | ||
| }); | ||
| }) | ||
| .setKeyPairsDispatcher(async (_, identifier) => { | ||
| if (identifier !== IDENTIFIER) { | ||
| return []; | ||
| } | ||
| const keyPairs = keyPairsStore.get(identifier); | ||
| if (keyPairs) { | ||
| return keyPairs; | ||
| } | ||
| const { privateKey, publicKey } = await generateCryptoKeyPair(); | ||
| keyPairsStore.set(identifier, [{ privateKey, publicKey }]); | ||
| return [{ privateKey, publicKey }]; | ||
| }); | ||
|
|
||
| federation | ||
| .setInboxListeners("/users/{identifier}/inbox", "/inbox") | ||
| .on(Follow, async (context, follow) => { | ||
| if ( | ||
| follow.id == null || | ||
| follow.actorId == null || | ||
| follow.objectId == null | ||
| ) { | ||
| return; | ||
| } | ||
| const result = context.parseUri(follow.objectId); | ||
| if (result?.type !== "actor" || result.identifier !== IDENTIFIER) { | ||
| return; | ||
| } | ||
| const follower = (await follow.getActor(context)) as Person; | ||
| if (!follower?.id || follower.id === null) { | ||
| throw new Error("follower is null"); | ||
| } | ||
| await context.sendActivity( | ||
| { identifier: result.identifier }, | ||
| follower, | ||
| new Accept({ | ||
| id: new URL( | ||
| `#accepts/${follower.id.href}`, | ||
| context.getActorUri(IDENTIFIER), | ||
| ), | ||
| actor: follow.objectId, | ||
| object: follow, | ||
| }), | ||
| ); | ||
| relationStore.set(follower.id.href, follower); | ||
| }) | ||
| .on(Undo, async (context, undo) => { | ||
| const activity = await undo.getObject(context); | ||
| if (activity instanceof Follow) { | ||
| if (activity.id == null) { | ||
| return; | ||
| } | ||
| if (undo.actorId == null) { | ||
| return; | ||
| } | ||
| relationStore.delete(undo.actorId.href); | ||
| } else { | ||
| console.debug(undo); | ||
| } | ||
| }); | ||
|
|
||
| federation.setObjectDispatcher( | ||
| Note, | ||
| "/users/{identifier}/posts/{id}", | ||
| (ctx, values) => { | ||
| return new Note({ | ||
| id: ctx.getObjectUri(Note, values), | ||
| attribution: ctx.getActorUri(values.identifier), | ||
| name: values.id, | ||
| }); | ||
| }, | ||
| ); | ||
|
|
||
| federation.setFollowersDispatcher( | ||
| "/users/{identifier}/followers", | ||
| () => { | ||
| const followers = Array.from(relationStore.values()); | ||
| const items: Recipient[] = followers.map((f) => ({ | ||
| id: f.id, | ||
| inboxId: f.inboxId, | ||
| endpoints: f.endpoints, | ||
| })); | ||
| return { items }; | ||
| }, | ||
| ); | ||
|
|
||
| export default federation; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import type { Person } from "@fedify/vocab"; | ||
|
|
||
| declare global { | ||
| var keyPairsStore: Map<string, CryptoKeyPair[]>; | ||
| var relationStore: Map<string, Person>; | ||
| } | ||
|
|
||
| export const keyPairsStore: Map<string, CryptoKeyPair[]> = | ||
| globalThis.keyPairsStore ?? new Map(); | ||
| export const relationStore: Map<string, Person> = globalThis.relationStore ?? | ||
| new Map(); | ||
|
|
||
| // This is just a hack for the demo. | ||
| // Never do this in production; use safe and secure storage. | ||
| globalThis.keyPairsStore = keyPairsStore; | ||
| globalThis.relationStore = relationStore; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| import { fedifyMiddleware } from "@fedify/solidstart"; | ||
| import federation from "../lib/federation"; | ||
|
|
||
| export default fedifyMiddleware(federation); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { Navigate } from "@solidjs/router"; | ||
|
|
||
| export default function Home() { | ||
| return <Navigate href="/users/demo" />; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Section heading is written as “Solidstart”, but the framework name is “SolidStart” elsewhere in the doc and in upstream branding. Please fix the capitalization for consistency/searchability.