Refactor Vite integration and update docs

Introduced a Vite adapter with "fresh" and "cached" modes, centralized dev server configuration, and streamlined the example setup. Updated documentation with detailed steps for Vite integration and revised the internal dev environment to align with the changes.
This commit is contained in:
dswbx
2025-01-10 09:46:00 +01:00
parent 0500d4fc8e
commit f0d502133e
7 changed files with 181 additions and 82 deletions

View File

@@ -1,10 +1,4 @@
import { serveStatic } from "@hono/node-server/serve-static";
import { createClient } from "@libsql/client/node";
import { App, registries } from "./src";
import { LibsqlConnection } from "./src/data";
import { StorageLocalAdapter } from "./src/media/storage/adapters/StorageLocalAdapter";
registries.media.register("local", StorageLocalAdapter);
import { serve } from "./src/adapter/vite";
const credentials = {
url: import.meta.env.VITE_DB_URL!,
@@ -14,22 +8,10 @@ if (!credentials.url) {
throw new Error("Missing VITE_DB_URL env variable. Add it to .env file");
}
const connection = new LibsqlConnection(createClient(credentials));
export default {
async fetch(request: Request) {
const app = App.create({ connection });
app.emgr.onEvent(
App.Events.AppBuiltEvent,
async () => {
app.registerAdminController({ forceDev: true });
app.module.server.client.get("/assets/*", serveStatic({ root: "./" }));
},
"sync"
);
await app.build();
return app.fetch(request);
}
};
export default serve({
connection: {
type: "libsql",
config: credentials
},
forceDev: true
});