choo-ssr-lbry
v0.3.0
Published
Choo plugin for SSR with Fastify
Downloads
9
Maintainers
Readme
choo-ssr
Server-side rendering for Choo with Fastify
Usage - Install - License: MIT
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