demo_network_visjs/server.tsx

46 lines
928 B
TypeScript
Raw Normal View History

2024-01-23 14:13:26 +01:00
import { bundle } from 'emit'
import ssr from 'preact-render-to-string'
import denoConfig from './deno.json' with { type: 'json' }
2024-01-23 15:13:01 +01:00
//only for deno compile (https://github.com/denoland/fresh/issues/785)
import * as React from 'preact/compat'
2024-01-23 14:30:10 +01:00
//Compile and bundle client script to js
2024-01-23 14:13:26 +01:00
const script = await bundle('./script.tsx', {
minify: true,
type: 'module',
compilerOptions: {
inlineSourceMap: true,
jsxFactory: 'h',
},
'importMap': { imports: denoConfig.imports },
})
2024-01-23 14:43:22 +01:00
const css = await Deno.readTextFile('./style.css')
2024-01-23 14:30:10 +01:00
/**
* Page template
*/
2024-01-23 14:13:26 +01:00
function Template() {
return (
<html lang='fr'>
<head>
<title>Démo</title>
</head>
2024-01-23 14:43:22 +01:00
<style>{css}</style>
2024-01-23 14:13:26 +01:00
<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',
},
})
)