项目作者: nearform

项目描述 :
Choo plugin for SSR with Fastify
高级语言: JavaScript
项目地址: git://github.com/nearform/choo-ssr.git
创建时间: 2018-03-27T09:28:14Z
项目社区:https://github.com/nearform/choo-ssr

开源协议:

下载


choo-ssr

Server-side rendering for Choo with Fastify

Usage -
Install -
License: MIT

stability
standard

Usage

See examples for more

  1. // app.js
  2. const choo = require('choo')
  3. const html = require('choo/html')
  4. const ssr = require('choo-ssr')
  5. function main () {
  6. const app = choo()
  7. const page = view => (
  8. ssr.html(
  9. ssr.head(ssr.state()),
  10. ssr.body(view)
  11. )
  12. )
  13. app.use(ssr())
  14. app.route('/', page(home))
  15. app.route('*', page(notfound))
  16. app.mount('html')
  17. function home (state, emit) {
  18. return html`<div>Hello World!</div>`
  19. }
  20. function notfound (state, emit) {
  21. return html`<div>Not found :(</div>`
  22. }
  23. return app
  24. }
  25. if (typeof window !== 'undefined') {
  26. main()
  27. }
  28. module.exports = main
  1. // server.js
  2. const fastify = require('fastify')()
  3. fastify.register(require('choo-ssr/fastify'), {
  4. app: require('./app'),
  5. })

Install

  1. npm install choo-ssr

License

MIT