Skip to content

Commit bf34eb6

Browse files
committed
fix: dev server
1 parent 703a8f2 commit bf34eb6

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

website/src/components/templates/BaseTemplate.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export const BaseTemplate: FC<BaseTemplateProps> = ({
8181
rel="icon"
8282
type="image/png"
8383
sizes="32x32"
84-
href="/assets/favicon.png"
84+
href={`${basePath.replace(/\/$/, "")}/favicon.png`}
8585
/>
8686
<link
8787
rel="preload"

website/src/components/ui/common/SearchWindow.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,22 @@ import { CloseIcon } from "../../icons";
55
export const SearchWindow: FC = () => {
66
return (
77
<div class="flex flex-col max-h-[80vh]">
8-
<link
9-
href={`${basePath.replace(/\/$/, "")}/pagefind/pagefind-ui.css`}
10-
rel="stylesheet"
11-
/>
12-
<script src={`${basePath.replace(/\/$/, "")}/pagefind/pagefind-ui.js`} />
8+
{import.meta.env.PROD && (
9+
<>
10+
<link
11+
href={`${basePath.replace(/\/$/, "")}/pagefind/pagefind-ui.css`}
12+
rel="stylesheet"
13+
/>
14+
<script
15+
src={`${basePath.replace(/\/$/, "")}/pagefind/pagefind-ui.js`}
16+
/>
17+
</>
18+
)}
1319
<div class="flex justify-between items-center p-4 border-b border-gray-200 flex-shrink-0">
14-
<h2 class="text-lg font-semibold">検索</h2>
20+
<h2 class="text-lg font-semibold">
21+
検索
22+
{import.meta.env.DEV && <span> - Search disabled on DEV</span>}
23+
</h2>
1524
<button
1625
type="button"
1726
class="text-gray-400 hover:text-gray-600"

website/src/index.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { serveStatic } from "@hono/node-server/serve-static";
12
import { Hono } from "hono";
23
import { appendTrailingSlash, trimTrailingSlash } from "hono/trailing-slash";
34
import {
@@ -24,7 +25,7 @@ const [flattenedPages, pagePaths] = flattenDocs(docs);
2425
const allRoutes = flattenedPages.map((page) => page.route);
2526
registerRoutes(allRoutes);
2627

27-
const app = new Hono();
28+
const app = new Hono().basePath(import.meta.env.DEV ? "/docs" : "/");
2829
app.use(appendTrailingSlash());
2930
app.use(trimTrailingSlash());
3031

@@ -47,7 +48,7 @@ flattenedPages.forEach((page, pageIndex) => {
4748

4849
// Remove basePath from the route if it starts with basePath.
4950
let route = page.route;
50-
if (import.meta.env.PROD && route.startsWith(basePath)) {
51+
if (route.startsWith(basePath)) {
5152
route = route.slice(basePath.length - (basePath.endsWith("/") ? 1 : 0));
5253
}
5354
app.get(route, (c) => {
@@ -74,4 +75,19 @@ flattenedPages.forEach((page, pageIndex) => {
7475
});
7576
});
7677

78+
if (import.meta.env.DEV) {
79+
app.use(
80+
"*",
81+
serveStatic({
82+
root: "./public",
83+
rewriteRequestPath: (path) => {
84+
return path.slice(basePath.length);
85+
},
86+
onNotFound: (path, c) => {
87+
console.log(`${path} is not found, request to ${c.req.path}`);
88+
},
89+
}),
90+
);
91+
}
92+
7793
export default app;

0 commit comments

Comments
 (0)