Formmating Changes

This commit is contained in:
2026-04-28 10:03:20 -07:00
parent afdfdd76ab
commit b8027deea4
2 changed files with 55 additions and 49 deletions

View File

@@ -1,4 +1,9 @@
preload = ["./bun_plugins/onStartup-post-importer.ts"] preload = [
"./bun_plugins/onStartup-post-importer.ts"
]
[serve.static] [serve.static]
plugins = ["./bun_plugins/onImport-markdown-loader.tsx", "./bun_plugins/onRuntime-external-urls.ts"] plugins = [
"./bun_plugins/onImport-markdown-loader.tsx",
"./bun_plugins/onRuntime-external-urls.ts"
]

View File

@@ -7,6 +7,54 @@ import { NotFound } from "./src/frontend/pages/not-found";
import { Post } from "./src/frontend/pages/post"; import { Post } from "./src/frontend/pages/post";
import { dbConnection } from "./src/db"; import { dbConnection } from "./src/db";
Bun.serve({
development: {
hmr: true,
console: true,
},
routes: {
// standard mounting of blog posts
...(await blogPosts(false)),
// hot module replacement in development mode
...(process.env.NODE_ENV === "development" ? (await blogPosts(true)) : {}),
// Home page
"/": (req: Request) => {
// Extract URL parameters from the request to pass to the component
const searchParams = new URLSearchParams(req.url.split('?')[1]);
if (req.headers.get("shell-loaded") === "true") {
return compressResponse(renderToString(<Home searchParams={searchParams} />));
}
return compressResponse(
renderToString(
<AppShell searchParams={searchParams}>
<Home searchParams={searchParams} />
</AppShell>,
)
);
},
"/profile-picture.webp": () => {
return new Response(Bun.file("./src/public/profile-picture.webp"), {
headers: {
"Content-Type": "image/webp",
},
});
},
"/healthz": new Response('ok'),
"/*": (req) => {
if(req.headers.get("shell-loaded") === "true") {
return compressResponse(renderToString(<NotFound />), 404);
}
return compressResponse(renderToString(<AppShell><NotFound /></AppShell>), 404);
}
},
});
function compressResponse(html: string, status?: number) { function compressResponse(html: string, status?: number) {
const compressed = Bun.gzipSync(Buffer.from(html)); const compressed = Bun.gzipSync(Buffer.from(html));
return new Response(compressed, { return new Response(compressed, {
@@ -78,50 +126,3 @@ async function blogPosts(hmr: boolean) {
}); });
return blogPosts; return blogPosts;
} }
Bun.serve({
development: {
hmr: true,
console: true,
},
routes: {
// standard mounting of blog posts
...(await blogPosts(false)),
// hot module replacement in development mode
...(process.env.NODE_ENV === "development" ? (await blogPosts(true)) : {}),
// Home page
"/": (req: Request) => {
// Extract URL parameters from the request to pass to the component
const searchParams = new URLSearchParams(req.url.split('?')[1]);
if (req.headers.get("shell-loaded") === "true") {
return compressResponse(renderToString(<Home searchParams={searchParams} />));
}
return compressResponse(
renderToString(
<AppShell searchParams={searchParams}>
<Home searchParams={searchParams} />
</AppShell>,
)
);
},
"/profile-picture.webp": () => {
return new Response(Bun.file("./src/public/profile-picture.webp"), {
headers: {
"Content-Type": "image/webp",
},
});
},
"/healthz": new Response('ok'),
"/*": (req) => {
if(req.headers.get("shell-loaded") === "true") {
return compressResponse(renderToString(<NotFound />), 404);
}
return compressResponse(renderToString(<AppShell><NotFound /></AppShell>), 404);
}
},
});