Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. const express = require('express');
  2. const htm = require('htm');
  3. const vhtml = require('vhtml');
  4.  
  5. // create an html`` tag function for vhtml:
  6. const html = htm.bind(vhtml);
  7.  
  8. const App = (props) => html`
  9. <div class="app">
  10. <h1>This is an app</h1>
  11. <p>Current server time: ${new Date + ''}</p>
  12. </div>
  13. `;
  14.  
  15. const app = express();
  16. app.get('/', (request, response) => {
  17. // html already returns a string!
  18. const body = html`<${App} url=${request.url} />`;
  19.  
  20. // wrap it in an HTML document and send it back
  21. response.send(`<!DOCTYPE html><html><body>${body}</body></html>`);
  22. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement