@squadbase/vite-server 0.1.19-dev.f16bde6 → 0.1.20-dev.39a001c

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,18 +1,23 @@
1
- // Server build entry used by `squadbasePlugin` (see vite-plugin.ts).
1
+ // Server entry used by squadbasePlugin for both the dev server and the build.
2
2
  //
3
- // It re-exports the vite-server app as default (so @hono/vite-build's injected
4
- // `serve({ fetch: app.fetch })` works), and statically imports the project's
5
- // TypeScript server-logic handlers via the `virtual:squadbase-server-logics`
6
- // module (generated by the plugin from `server-logic/*.json`). Because the
7
- // handlers are compiled into THIS bundle, they share the server's module graph
8
- // — in particular hono's `contextStorage` AsyncLocalStorage — so `getContext()`
9
- // works. This replaces runtime jiti transpilation.
3
+ // It imports the app and the server-logic files collected by `import.meta.glob`
4
+ // (via the `virtual:squadbase-server-logics` module), populates the registry,
5
+ // and re-exports the app as default. Because the handlers are collected through
6
+ // the same Vite module graph as the server, hono's context storage resolves to a
7
+ // single instance and `getContext` works.
10
8
  //
11
- // Registration goes through `@squadbase/vite-server/main` (not `/`) because
12
- // `./main` and `./` are separate bundle entry points with separate module state.
13
- import app, { registerBundledHandlers } from "@squadbase/vite-server/main";
14
- import { HANDLERS } from "virtual:squadbase-server-logics";
9
+ // Population goes through `@squadbase/vite-server/main` (not `.`) so it targets the
10
+ // same module instance as the running app.
11
+ import { serve } from "@hono/node-server";
12
+ import app, { populateServerLogics } from "@squadbase/vite-server/main";
13
+ import { handlerModules, metaModules } from "virtual:squadbase-server-logics";
15
14
 
16
- registerBundledHandlers(HANDLERS);
15
+ populateServerLogics({ handlerModules, metaModules });
16
+
17
+ // In the built (production) server, start the Node HTTP server. In dev the app is
18
+ // served by @hono/vite-dev-server via `app.fetch`, so `serve()` must NOT run there.
19
+ if (import.meta.env.PROD) {
20
+ serve({ fetch: app.fetch, port: Number(process.env.PORT) || 3000 });
21
+ }
17
22
 
18
23
  export default app;