|
1 | | -import { staticPlugin } from '@elysiajs/static'; |
2 | | -import Elysia from 'elysia'; |
3 | | -import { router, trpcRouter } from './backend/src/router'; |
4 | | -import { StaticRouter } from 'react-router-dom'; |
5 | | -import React from 'react'; |
6 | | -import { App, OuterHtml } from './app'; |
7 | | -// @ts-expect-error - have to import from server.browser for some reason |
8 | | -import { renderToReadableStream } from 'react-dom/server.browser'; |
| 1 | +import { router } from './backend/src/router'; |
| 2 | +import { createBunHttpHandler } from 'trpc-bun-adapter'; |
| 3 | +import { serve } from 'bun'; |
| 4 | +import index from './public/index.html'; |
9 | 5 |
|
10 | | -await Bun.build({ |
11 | | - entrypoints: ['./client.tsx'], |
12 | | - outdir: './public', |
13 | | - minify: true, |
14 | | - target: 'bun' |
15 | | -}); |
16 | | - |
17 | | -const app = new Elysia() |
18 | | - .get('/health', () => 'healthy') |
19 | | - .use(trpcRouter(router)) |
20 | | - .use(staticPlugin()) |
21 | | - .get('*', async context => { |
22 | | - const stream = await renderToReadableStream( |
23 | | - <StaticRouter location={context.path}> |
24 | | - <OuterHtml> |
25 | | - <App |
26 | | - bucket={context.query.bucket} |
27 | | - commitHash={context.query.commitHash} |
28 | | - diffId={context.query.diffId} |
29 | | - /> |
30 | | - {process.env.NODE_ENV === 'development' && ( |
31 | | - <script src="https://cdn.tailwindcss.com" /> |
32 | | - )} |
33 | | - </OuterHtml> |
34 | | - </StaticRouter>, |
35 | | - { |
36 | | - bootstrapScripts: ['./public/client.js'] |
37 | | - } |
| 6 | +const server = serve({ |
| 7 | + static: { |
| 8 | + '/': index |
| 9 | + }, |
| 10 | + port: process.env.PORT ?? 8080, |
| 11 | + async fetch(request, response) { |
| 12 | + const trpcHandler = createBunHttpHandler({ router, endpoint: '/trpc' }); |
| 13 | + return ( |
| 14 | + trpcHandler(request, response) ?? |
| 15 | + new Response('Not found', { status: 404 }) |
38 | 16 | ); |
39 | | - return new Response(stream, { |
40 | | - headers: { 'Content-Type': 'text/html' } |
41 | | - }); |
42 | | - }) |
43 | | - .listen(process.env.PORT ?? 8080); |
| 17 | + }, |
| 18 | + development: process.env.NODE_ENV === 'development' |
| 19 | +}); |
44 | 20 |
|
45 | | -console.info( |
46 | | - `App is running at http://${app.server?.hostname}:${app.server?.port}` |
47 | | -); |
| 21 | +console.log(`Server running at ${server.url}`); |
0 commit comments