demo_network_visjs/server.tsx
2024-01-23 14:30:10 +01:00

40 lines
741 B
TypeScript

import { bundle } from 'emit'
import ssr from 'preact-render-to-string'
import denoConfig from './deno.json' with { type: 'json' }
//Compile and bundle client script to js
const script = await bundle('./script.tsx', {
minify: true,
type: 'module',
compilerOptions: {
inlineSourceMap: true,
jsxFactory: 'h',
},
'importMap': { imports: denoConfig.imports },
})
/**
* Page template
*/
function Template() {
return (
<html lang='fr'>
<head>
<title>Démo</title>
</head>
<body>
</body>
<script type='module' dangerouslySetInnerHTML={{ __html: script.code }}>
</script>
</html>
)
}
Deno.serve(() =>
new Response(ssr(<Template />), {
headers: {
'Content-Type': 'text/html; charset=utf-8',
},
})
)