forked from mggower/vno
-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
server.ts
39 lines (28 loc) · 945 Bytes
/
server.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
import { opine, serveStatic } from "https://deno.land/x/[email protected]/mod.ts";
import vueServerRenderer from 'https://deno.land/x/vue_server_renderer@/mod.js';
import App from './vno-ssr/build.js';
import { join, dirname} from "https://deno.land/[email protected]/path/mod.ts";
import styles from './vno-ssr/style.js'
const port = 3000
const app = opine();
app.use(serveStatic('vno-build'));
const __dirname = dirname(import.meta.url);
app.use("/", (req, res, next) => {
let rendered;
vueServerRenderer(App, (err:any, res:any) => {
rendered = res;
});
const html =
`<html>
<head>
${styles}
</head>
<body>
<div id="root">${rendered}</div>
<script type="module" src="./build.js"></script>
</body>
</html>`;
res.type("text/html").send(html);
});
app.listen({ port });
console.log(`Vue SSR App listening on port ${port}`);