This commit is contained in:
Mythie
2025-01-07 12:45:53 +11:00
parent 866b036484
commit 84ad7a6c2b
6 changed files with 58 additions and 28 deletions

View File

@ -3,15 +3,17 @@ import { type HttpBindings } from '@hono/node-server';
import { Hono } from 'hono';
import { reactRouter } from 'remix-hono/handler';
type Bindings = HttpBindings;
import { IS_APP_WEB } from '@documenso/lib/constants/app';
const app = new Hono<{ Bindings: Bindings }>();
console.log({ IS_APP_WEB });
type Bindings = HttpBindings;
const isProduction = process.env.NODE_ENV === 'production';
const viteDevServer = isProduction
? undefined
: await import('vite').then(async (vite) =>
: import('vite').then(async (vite) =>
vite.createServer({
server: { middlewareMode: true },
}),
@ -23,23 +25,29 @@ const reactRouterMiddleware = remember('reactRouterMiddleware', async () =>
build: isProduction
? // @ts-expect-error build/server/index.js is a build artifact
await import('../build/server/index.js')
: async () => viteDevServer!.ssrLoadModule('virtual:react-router/server-build'),
: async () => (await viteDevServer)!.ssrLoadModule('virtual:react-router/server-build'),
}),
);
// app.get('/', (c) => c.text('Hello, world!'));
if (viteDevServer) {
app.use('*', async (c, next) => {
return new Promise((resolve) => {
viteDevServer.middlewares(c.env.incoming, c.env.outgoing, () => resolve(next()));
export const getApp = async () => {
const app = new Hono<{ Bindings: Bindings }>();
const resolvedDevServer = await viteDevServer;
// app.get('/', (c) => c.text('Hello, world!'));
if (resolvedDevServer) {
app.use('*', async (c, next) => {
return new Promise((resolve) => {
resolvedDevServer.middlewares(c.env.incoming, c.env.outgoing, () => resolve(next()));
});
});
}
app.use('*', async (c, next) => {
const middleware = await reactRouterMiddleware;
return middleware(c, next);
});
}
app.use('*', async (c, next) => {
const middleware = await reactRouterMiddleware;
return middleware(c, next);
});
export default app;
return app;
};