choo-ssr

0.2.2 • Public • Published

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

Package Sidebar

Install

npm i choo-ssr

Weekly Downloads

1

Version

0.2.2

License

MIT

Unpacked Size

113 kB

Total Files

19

Last publish

Collaborators

  • diffcunha
  • goto-bus-stop
  • matteo.collina