Replace Elysia with bun.serve for hot reloading and static serving
This commit is contained in:
71
index.tsx
71
index.tsx
@@ -1,28 +1,49 @@
|
||||
import { Elysia } from "elysia";
|
||||
import { html } from "@elysiajs/html";
|
||||
import { staticPlugin } from "@elysiajs/static";
|
||||
// import { Elysia } from "elysia";
|
||||
// import { html } from "@elysiajs/html";
|
||||
// import { staticPlugin } from "@elysiajs/static";
|
||||
|
||||
import { AppShell } from "./src/frontend/AppShell";
|
||||
import { app } from "./src/backend";
|
||||
// import { AppShell } from "./src/frontend/AppShell";
|
||||
// import { app } from "./src/backend";
|
||||
|
||||
const index = new Elysia()
|
||||
.use(html())
|
||||
.onRequest(({ request }) => {
|
||||
console.log(`Request ${request.method} ${request.url}`);
|
||||
})
|
||||
.onAfterHandle(({ request, responseValue }) => {
|
||||
if (request.headers.get("shell-loaded") === "true") {
|
||||
return responseValue; // Return the <main> element if the AppShell has already been loaded
|
||||
}
|
||||
return AppShell(responseValue); // Return the <main> element wrapped by the AppShell
|
||||
})
|
||||
.use(staticPlugin({
|
||||
assets: './src/public',
|
||||
prefix: '/public'
|
||||
}))
|
||||
.use(app)
|
||||
.listen(3000);
|
||||
// const index = new Elysia()
|
||||
// .use(html())
|
||||
// .onRequest(({ request }) => {
|
||||
// console.log(`Request ${request.method} ${request.url}`);
|
||||
// })
|
||||
// .onAfterHandle(({ request, responseValue }) => {
|
||||
// if (request.headers.get("shell-loaded") === "true") {
|
||||
// return responseValue; // Return the <main> element if the AppShell has already been loaded
|
||||
// }
|
||||
// return AppShell(responseValue); // Return the <main> element wrapped by the AppShell
|
||||
// })
|
||||
// .use(staticPlugin({
|
||||
// assets: './src/public',
|
||||
// prefix: '/public'
|
||||
// }))
|
||||
// .use(app)
|
||||
// .listen(3000);
|
||||
|
||||
console.log(
|
||||
`🦊 Elysia is running at ${index.server?.hostname}:${index.server?.port}`
|
||||
);
|
||||
// console.log(
|
||||
// `🦊 Elysia is running at ${index.server?.hostname}:${index.server?.port}`
|
||||
// );
|
||||
|
||||
|
||||
import { serve } from "bun";
|
||||
import AppShell from "./temp/appshell.html"
|
||||
|
||||
// Dynamically import all markdown files
|
||||
const glob = new Bun.Glob("**/*.md");
|
||||
const routes: Record<string, any> = {
|
||||
'/': AppShell,
|
||||
};
|
||||
|
||||
for await (const file of glob.scan("./content")) {
|
||||
const post = await import(`./content/${file}`, { with: { type: "html" } });
|
||||
const route = `/${file.replace(/\.md$/, '')}`;
|
||||
routes[route] = post.default;
|
||||
}
|
||||
|
||||
serve({
|
||||
routes,
|
||||
development: true,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user