0.2.2 • Published 4 years ago

choo-ssr v0.2.2

Weekly downloads
8
License
MIT
Repository
github
Last release
4 years ago

choo-ssr

Server-side rendering for Choo with Fastify

Usage - Install - License: MIT

stability standard

Usage

See examples for more

// app.js

const choo = require('choo')
const html = require('choo/html')
const ssr = require('choo-ssr')

function main () {
  const app = choo()

  const page = view => (
    ssr.html(
      ssr.head(ssr.state()),
      ssr.body(view)
    )
  )

  app.use(ssr())
  app.route('/', page(home))
  app.route('*', page(notfound))
  app.mount('html')

  function home (state, emit) {
    return html`<div>Hello World!</div>`
  }

  function notfound (state, emit) {
    return html`<div>Not found :(</div>`
  }

  return app
}


if (typeof window !== 'undefined') {
  main()
}

module.exports = main
// server.js
const fastify = require('fastify')()

fastify.register(require('choo-ssr/fastify'), {
  app: require('./app'),
})

Install

npm install choo-ssr

License

MIT