Skip to content

Commit d19e461

Browse files
committed
Server: support handlerRequest()
1 parent 04d3a75 commit d19e461

File tree

20 files changed

+12643
-4061
lines changed

20 files changed

+12643
-4061
lines changed

.changeset/quiet-dodos-kneel.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@fuma-comment/server": minor
3+
"@fuma-comment/react": minor
4+
"@fuma-comment/next": minor
5+
---
6+
7+
Move method handlers of `CustomComment()` to `.methods`

apps/docs/content/docs/hono.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ HonoComment({
1818
storage: // storage adapter
1919
auth: // auth adapter
2020
});
21-
```
21+
```

apps/docs/content/docs/image-upload.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const storage: StorageContext = {
5050
{
5151
method: "POST",
5252
body,
53-
}
53+
},
5454
);
5555

5656
if (res.ok) {

apps/docs/content/docs/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ const app = new Elysia()
203203
// or other prefix if you wanted
204204
prefix: "/api/comments",
205205
},
206-
})
206+
}),
207207
)
208208
.listen(8080);
209209

packages/next/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
"author": "Fuma Nama",
88
"homepage": "https://fuma-comment.vercel.app",
99
"repository": "https://github.com/fuma-nama/fuma-comment",
10-
"files": [
11-
"./dist"
12-
],
10+
"files": ["./dist"],
1311
"license": "MIT",
1412
"scripts": {
1513
"lint": "biome lint .",

packages/react/package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
"author": "Fuma Nama",
77
"homepage": "https://fuma-comment.vercel.app",
88
"repository": "https://github.com/fuma-nama/fuma-comment",
9-
"files": [
10-
"./dist",
11-
"./css"
12-
],
9+
"files": ["./dist", "./css"],
1310
"license": "MIT",
1411
"type": "module",
1512
"exports": {

packages/react/src/components/comment/content-renderer.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,10 @@ export function ContentRenderer({
195195
function CodeBlock({
196196
language,
197197
content,
198-
}: { language: string; content: string }) {
198+
}: {
199+
language: string;
200+
content: string;
201+
}) {
199202
const tree = lowlight.highlight(
200203
lowlight.registered(language) ? language : "plaintext",
201204
content,

packages/react/src/components/editor/image-upload.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ import { ImageIcon } from "lucide-react";
1818

1919
export default function UploadImageButton({
2020
editor,
21-
}: { editor: Editor }): React.ReactElement {
21+
}: {
22+
editor: Editor;
23+
}): React.ReactElement {
2224
useHookUpdate(editor);
2325
const [isOpen, setIsOpen] = useState(false);
2426

packages/react/src/components/timestamp.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import { toLocalString } from "../utils/date";
44

55
export function Timestamp({
66
timestamp,
7-
}: { timestamp: Date | string }): React.ReactNode {
7+
}: {
8+
timestamp: Date | string;
9+
}): React.ReactNode {
810
const [str, setStr] = useState("");
911

1012
useLayoutEffect(() => {
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { createServerRoute } from "@tanstack/react-start/server";
2+
import type { CustomCommentOptions, CustomRequest } from "../src/custom";
3+
import { CustomComment } from "../src/custom";
4+
import { mockAdapter } from "../test/utils";
5+
6+
// Define the request type for Tanstack Start
7+
export type TanstackRequest = CustomRequest & {
8+
// Optionally, you can add Tanstack-specific context here if needed
9+
};
10+
11+
export type TanstackCommentOptions = CustomCommentOptions<TanstackRequest>;
12+
13+
const comment = CustomComment<TanstackRequest>({
14+
storage: mockAdapter,
15+
auth: {
16+
getSession() {
17+
return null
18+
},
19+
}
20+
});
21+
22+
async function endpoint({
23+
request,
24+
params,
25+
}: { request: Request; params: Record<string, string> }) {
26+
const res = await comment.handleRequest(
27+
request.method,
28+
params._splat,
29+
(params) => ({
30+
method: request.method,
31+
body() {
32+
return request.json();
33+
},
34+
headers: request.headers,
35+
params,
36+
queryParams: new URL(request.url).searchParams,
37+
}),
38+
);
39+
40+
if (!res) {
41+
return new Response("Not Found", {
42+
status: 404,
43+
});
44+
}
45+
46+
if (res.type === "success") {
47+
return Response.json(res.data);
48+
}
49+
50+
return Response.json(res.data, { status: res.status });
51+
}
52+
53+
export const ServerRoute = createServerRoute("/api/comments/$").methods({
54+
GET: endpoint,
55+
DELETE: endpoint,
56+
POST: endpoint,
57+
PATCH: endpoint,
58+
PUT: endpoint,
59+
});

0 commit comments

Comments
 (0)