htm-ssr-direct.js

September 5, 2019 ยท View on GitHub

const express = require('express'); const htm = require('htm'); const vhtml = require('vhtml');

// create an html`` tag function for vhtml: const html = htm.bind(vhtml);

const App = (props) => html`

This is an app

Current server time: ${new Date + ''}

`;

const app = express(); app.get('/', (request, response) => { // html already returns a string! const body = html<${App} url=${request.url} />;

// wrap it in an HTML document and send it back response.send(<!DOCTYPE html><html><body>${body}</body></html>); });