diff --git a/bunfig.toml b/bunfig.toml
index 3857786..620c3a8 100644
--- a/bunfig.toml
+++ b/bunfig.toml
@@ -1,4 +1,9 @@
-preload = ["./bun_plugins/onStartup-post-importer.ts"]
+preload = [
+ "./bun_plugins/onStartup-post-importer.ts"
+]
[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"
+]
diff --git a/index.tsx b/index.tsx
index 5705267..843e79d 100644
--- a/index.tsx
+++ b/index.tsx
@@ -7,6 +7,54 @@ import { NotFound } from "./src/frontend/pages/not-found";
import { Post } from "./src/frontend/pages/post";
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());
+ }
+
+ return compressResponse(
+ renderToString(
+
+
+ ,
+ )
+ );
+ },
+ "/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(), 404);
+ }
+ return compressResponse(renderToString(), 404);
+ }
+ },
+});
+
+
function compressResponse(html: string, status?: number) {
const compressed = Bun.gzipSync(Buffer.from(html));
return new Response(compressed, {
@@ -78,50 +126,3 @@ async function blogPosts(hmr: boolean) {
});
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());
- }
-
- return compressResponse(
- renderToString(
-
-
- ,
- )
- );
- },
- "/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(), 404);
- }
- return compressResponse(renderToString(), 404);
- }
- },
-});