Skip to content

Commit 0c631c2

Browse files
committed
docs: move api to hono router
1 parent b187fb8 commit 0c631c2

File tree

11 files changed

+409
-390
lines changed

11 files changed

+409
-390
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
"@resolid/config": "^5.0.2",
2727
"@svitejs/changesets-changelog-github-compact": "^1.2.0",
2828
"@tailwindcss/language-server": "^0.14.29",
29-
"@types/node": "^24.10.15",
29+
"@types/node": "^24.11.0",
3030
"eslint-plugin-react-hooks": "^7.0.1",
3131
"eslint-plugin-react-you-might-not-need-an-effect": "^0.9.1",
32-
"lefthook": "^2.1.1",
32+
"lefthook": "^2.1.2",
3333
"oxfmt": "^0.35.0",
34-
"oxlint": "^1.50.0",
34+
"oxlint": "^1.51.0",
3535
"typescript": "^5.9.3"
3636
},
3737
"engines": {

packages/react-ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"typecheck": "tsc --noEmit"
4848
},
4949
"dependencies": {
50-
"@floating-ui/react": "^0.27.18",
50+
"@floating-ui/react": "^0.27.19",
5151
"@formkit/tempo": "^1.0.0",
5252
"@resolid/utils": "^1.2.7",
5353
"@tanstack/react-virtual": "^3.13.19",

pnpm-lock.yaml

Lines changed: 362 additions & 335 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

website/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
"@mdx-js/rollup": "^3.1.1",
2929
"@react-router/dev": "^7.13.1",
3030
"@resolid/config": "^5.0.2",
31-
"@resolid/dev": "^0.2.0",
32-
"@shikijs/rehype": "^3.23.0",
31+
"@resolid/dev": "^0.3.1",
32+
"@shikijs/rehype": "^4.0.1",
3333
"@tailwindcss/vite": "^4.2.1",
3434
"@types/react": "^19.2.14",
3535
"@types/react-dom": "^19.2.3",

website/src/api/search.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { getSearchData } from "~/utils/mdx-utils.server";
2+
3+
export async function search(keyword: string | undefined) {
4+
const result = await getSearchData(keyword ?? "");
5+
6+
return result.map((r) => ({ value: r.id, label: r.title, description: r.description }));
7+
}
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import { env } from "node:process";
2-
import type { Route } from "./+types/uploadthing";
3-
4-
export const action = async ({ request }: Route.ActionArgs) => {
5-
const params = new URL(request.url).searchParams;
6-
const act = params.get("act");
72

3+
export async function uploadthing(act: string | undefined, data: FormData) {
84
if (act == "getPrepareUrl") {
9-
const data = await request.formData();
10-
115
return await fetch("https://api.uploadthing.com/v7/prepareUpload", {
126
method: "POST",
137
headers: {
@@ -24,17 +18,15 @@ export const action = async ({ request }: Route.ActionArgs) => {
2418
}
2519

2620
if (act == "deleteFile") {
27-
const id = params.get("id");
28-
2921
return await fetch("https://api.uploadthing.com/v6/deleteFiles", {
3022
method: "POST",
3123
headers: {
3224
"content-type": "application/json",
3325
"X-Uploadthing-Api-Key": env.UPLOADTHING_API_KEY,
3426
} as unknown as Headers,
3527
body: JSON.stringify({
36-
customIds: [id],
28+
customIds: [data.get("id")],
3729
}),
3830
});
3931
}
40-
};
32+
}

website/src/components/site-search.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
} from "@resolid/react-ui";
1313
import { debounce } from "@resolid/utils";
1414
import { useState } from "react";
15-
import { useFetcher } from "react-router";
1615
import { HistoryLink } from "~/components/history-link";
1716
import { SpriteIcon } from "~/components/sprite-icon";
1817

@@ -26,11 +25,13 @@ export const SiteSearch = () => {
2625
}
2726
});
2827

29-
const { data, load } = useFetcher<{ value: string; label: string; description: string }[]>();
28+
const [data, setData] = useState<{ value: string; label: string; description: string }[]>();
3029

3130
const handleChange = debounce(async (value) => {
3231
if (value != "") {
33-
await load(`/api/search?q=${value}`);
32+
const result = await fetch(`/api/search?q=${value}`);
33+
34+
setData(await result.json());
3435
}
3536
}, 500);
3637

website/src/root.tsx

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
import type { PropsWithChildren } from "react";
22
import { ConfigProvider } from "@resolid/react-ui";
33
import zhCN from "@resolid/react-ui/locales/zh-CN";
4-
import { Links, type LinksFunction, Meta, Outlet, Scripts, ScrollRestoration } from "react-router";
4+
import { Meta, Outlet, Scripts, ScrollRestoration } from "react-router";
55
import { ErrorComponent } from "~/components/error-component";
66
import { RouteProcessBar } from "~/components/route-process-bar";
77
import { SiteLayout } from "~/components/site-layout";
88
import { VercelAnalytics } from "~/components/vercel-analytics";
99

10-
import styles from "~/root.css?url";
11-
12-
// noinspection JSUnusedGlobalSymbols
13-
export const links: LinksFunction = () => [
14-
{
15-
rel: "stylesheet",
16-
href: styles,
17-
},
18-
];
10+
import style from "~/root.css?url";
1911

2012
// noinspection JSUnusedGlobalSymbols
2113
export const meta = () => [
@@ -41,7 +33,7 @@ export const Layout = ({ children }: PropsWithChildren) => {
4133
<link rel="icon" href="/favicon.svg" sizes="any" type="image/svg+xml" />
4234
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
4335
<Meta />
44-
<Links />
36+
<link rel="stylesheet" href={style} />
4537
</head>
4638
<body className="min-h-screen overflow-y-scroll">
4739
<RouteProcessBar />
@@ -50,7 +42,7 @@ export const Layout = ({ children }: PropsWithChildren) => {
5042
</ConfigProvider>
5143
<ScrollRestoration />
5244
<Scripts />
53-
{!!import.meta.env.VITE_VERCEL_URL && (
45+
{import.meta.env.RESOLID_PLATFORM == "vercel" && (
5446
<VercelAnalytics endpoint="/growth" scriptSrc="/growth/script.js" />
5547
)}
5648
</body>

website/src/routes/api/search.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

website/src/server.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
import { createServer, nodeConfig, vercelConfig } from "@resolid/dev/server";
2-
import { env } from "node:process";
1+
import {
2+
createHonoVercelServer,
3+
createHonoNodeServer,
4+
type Hono,
5+
type Env,
6+
} from "@resolid/dev/http.server";
7+
import { search } from "~/api/search";
8+
import { uploadthing } from "~/api/uploadthing";
39

4-
export default await createServer((platform) => {
5-
switch (platform) {
6-
case "vercel":
7-
return vercelConfig({});
10+
const configure = <E extends Env>(app: Hono<E>) => {
11+
app.get("/api/search", async (c) => c.json(await search(c.req.query("q"))));
12+
app.post(
13+
"/api/uploadthing",
14+
async (c) => await uploadthing(c.req.query("act"), await c.req.formData()),
15+
);
16+
};
817

9-
default:
10-
return nodeConfig({
11-
port: env.SERVER_PORT,
12-
});
13-
}
14-
});
18+
export default await (import.meta.env.RESOLID_PLATFORM == "vercel"
19+
? createHonoVercelServer({ configure })
20+
: createHonoNodeServer({ configure }));

0 commit comments

Comments
 (0)