-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
39 lines (33 loc) · 1 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { Elysia } from 'elysia';
import { staticPlugin } from '@elysiajs/static';
import { html } from '@elysiajs/html';
import { renderToString } from 'react-dom/server';
// @ts-ignore
import { renderToStringAsync } from 'react-async-ssr';
import { BeepSimulator } from './src/components/simulator';
const app = new Elysia().
use(staticPlugin({ assets: './src' })).
use(html());
const PORT = process.env.PORT || 4200;
const rendered = renderToStringAsync(BeepSimulator());
const component = await Bun.file('./src/components/simulator.jsx').text().then((data) => renderToString(data))
const htmlData = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="static/style.css">
</head>
<body>
<div id="root">
${rendered}
</div>
</body>
</html>
`
app.get("/", () => {
return htmlData;
})
.get("/static/style.css", () => Bun.file('./src/static/style.css'));
app.listen(PORT);