wip: New Application Architecture
Explore a new approach to clean up the implementation of an AppShell and individual pages. Will likely retire htmx for a lightweight custom page router.
This commit is contained in:
28
index.tsx
Normal file
28
index.tsx
Normal file
@@ -0,0 +1,28 @@
|
||||
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";
|
||||
|
||||
const index = new Elysia()
|
||||
.use(html())
|
||||
.onRequest(({ request }) => {
|
||||
console.log(`Request ${request.method} ${request.url}`);
|
||||
})
|
||||
.onAfterHandle(({ request, responseValue }) => {
|
||||
if (request.headers.get("hx-request") === "true") {
|
||||
return responseValue; // Return the <main> element if the request is an HTMX request
|
||||
}
|
||||
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}`
|
||||
);
|
||||
Reference in New Issue
Block a user