Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. const renderer = createRenderer({
  2. template: require('fs').readFileSync('./index.template.html', 'utf-8')
  3. })
  4.  
  5. renderer.renderToString(app, (err, html) => {
  6. console.log(html) // will be the full page with app content injected.
  7. })
  8.  
  9. const Vue = require("vue");
  10. const server = require("express")();
  11. const vsr = require("vue-server-renderer");
  12.  
  13. server.get("*", (req, res) => {
  14. const app = new Vue({
  15. data: {
  16. url: req.url
  17. }
  18. });
  19.  
  20. const renderer = vsr.createRenderer({
  21. template: require("fs").readFileSync("./index.template.html", "utf-8")
  22. });
  23.  
  24. renderer.renderToString(app, (err, html) => {
  25. console.log(html); // will be the full page with app content injected.
  26. res.send(html);
  27. });
  28. });
  29.  
  30. server.listen(8080);
  31.  
  32. undefined
  33. undefined
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement