Neologistic Paraphasic Mumbling

    This package has been deprecated

    Author message:

    This package has been renamed to fastify-nextjs

    fastify-react
    TypeScript icon, indicating that this package has built-in type declarations

    3.0.0 • Public • Published

    fastify-react

    Greenkeeper badge

    js-standard-style Build Status

    React server side rendering support for Fastify with Next Framework.

    Install

    npm i fastify-react next --save
    

    Usage

    Since Next needs some time to be ready on the first launch, you must declare your routes inside the after callback, after you registered the plugin.
    The plugin will expose the api next in Fastify that will handle the rendering for you.

    const fastify = require('fastify')()
     
    fastify
      .register(require('fastify-react'))
      .after(() => {
        fastify.next('/hello')
      })
     
    fastify.listen(3000, err => {
      if (err) throw err
      console.log('Server listenging on http://localhost:3000')
    })

    All you server rendered pages must be saved in the folder pages, as you can see in the next documentation.

    // /pages/hello.js
    export default () => <div>hello world</div>

    If you need to pass custom options to next just pass them to register as second parameter.

    fastify.register(require('fastify-react'), { dev: true })

    If you need to handle yourself the render part, just pass a callback to next:

    fastify.next('/hello', (app, req, reply) => {
      // your code
      // `app` is the Next instance
      app.render(req.raw, reply.res, '/hello', req.query, {})
    })

    Acknowledgements

    This project is kindly sponsored by:

    License

    Licensed under MIT.

    Install

    npm i fastify-react

    DownloadsWeekly Downloads

    3

    Version

    3.0.0

    License

    MIT

    Unpacked Size

    11.8 kB

    Total Files

    11

    Last publish

    Collaborators

    • galvez
    • simenb
    • coopflow
    • simoneb
    • rafaelgss
    • starptech
    • delvedor
    • matteo.collina
    • allevo
    • jsumners
    • zekth
    • eomm
    • fox1t
    • davidmarkclements
    • airhorns
    • kibertoad
    • climba03003