Advertisement
Guest User

Untitled

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