All Projects → fastify → Fastify Nextjs

fastify / Fastify Nextjs

Licence: mit
React server side rendering support for Fastify with Next

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Fastify Nextjs

V2raycloudspider
采集免费、优质的机场订阅连接;科学上网,从娃娃抓起!/SSR/V2RAY/TROJAN/SPIDER
Stars: ✭ 189 (-12.5%)
Mutual labels:  ssr
Blog Frontend Project
Web frontend code for my blogs, develop with Vue.
Stars: ✭ 206 (-4.63%)
Mutual labels:  ssr
Firebase Functions Next Example
Host a Next.js SSR React app on Cloud Functions for Firebase with Firebase Hosting
Stars: ✭ 215 (-0.46%)
Mutual labels:  ssr
Next Firebase Ssr
An Next.js example repo for building authenticated pages with Firebase Authentication, cookies, and getServerSideProps
Stars: ✭ 192 (-11.11%)
Mutual labels:  ssr
Next Routes
Universal dynamic routes for Next.js
Stars: ✭ 2,354 (+989.81%)
Mutual labels:  ssr
Vue Ssr Jit
A just in time compilation technique for server-side rendering
Stars: ✭ 209 (-3.24%)
Mutual labels:  ssr
Crate
👕 👖 📦 A sample web and mobile application built with Node, Express, React, React Native, Redux and GraphQL. Very basic replica of stitchfix.com / krate.in (allows users to get monthly subscription of trendy clothes and accessories).
Stars: ✭ 2,281 (+956.02%)
Mutual labels:  ssr
Hydux
A light-weight type-safe Elm-like alternative for Redux ecosystem, inspired by hyperapp and Elmish
Stars: ✭ 216 (+0%)
Mutual labels:  ssr
React Ssr
React 服务端渲染(SSR),react + redux + koa2 + sequelize + mysql全栈项目(Full Stack)
Stars: ✭ 205 (-5.09%)
Mutual labels:  ssr
Next Blog
基于react(ssr)服务端框架next.js和antd-design搭建的个人博客
Stars: ✭ 214 (-0.93%)
Mutual labels:  ssr
Accounts Ui
Accounts UI for React in Meteor 1.3+
Stars: ✭ 197 (-8.8%)
Mutual labels:  ssr
Ssr subscrible tool
SSR节点订阅地址生成器
Stars: ✭ 198 (-8.33%)
Mutual labels:  ssr
Shadowsocksbio
记录一下Shadowsocks的前世今生,以及一个简单的教程总结
Stars: ✭ 2,518 (+1065.74%)
Mutual labels:  ssr
Sgo
A dev server for rapid prototyping. Setting a directory to a static server.It provides a 404 neat interface for listing the directory's contents and switching into sub folders.
Stars: ✭ 194 (-10.19%)
Mutual labels:  ssr
Hapi Universal Redux
DEPRECATED: Create an universal React and Redux app in less than 5 minutes!
Stars: ✭ 215 (-0.46%)
Mutual labels:  ssr
Celestite
Beautifully reactive, server-side rendered Svelte apps w/ a Crystal backend
Stars: ✭ 185 (-14.35%)
Mutual labels:  ssr
Mordred
[Experimental] Source data from anywhere, for Next.js, Nuxt.js, Eleventy and many more.
Stars: ✭ 208 (-3.7%)
Mutual labels:  ssr
React Rendering Strategies
Improve your React ⚛️ app performance by using Dynamic Rendering, Progressive Rendering or Static Rendering
Stars: ✭ 217 (+0.46%)
Mutual labels:  ssr
React Pwa
An upgradable boilerplate for Progressive web applications (PWA) with server side rendering, build with SEO in mind and achieving max page speed and optimized user experience.
Stars: ✭ 2,433 (+1026.39%)
Mutual labels:  ssr
React Ssr News
Server Side Rendering for React demo project
Stars: ✭ 213 (-1.39%)
Mutual labels:  ssr

fastify-nextjs

js-standard-style CI workflow

React server side rendering support for Fastify with Next Framework.

Install

npm i fastify-nextjs next react react-dom --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-nextjs'))
  .after(() => {
    fastify.next('/hello')
  })

fastify.listen(3000, err => {
  if (err) throw err
  console.log('Server listening 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-nextjs'), { dev: true })

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

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

If you need to render with Next from within a custom handler (such as an error handler), use reply.renderNext

app.setErrorHandler((err, req, reply) => {
  reply.status(err.statusCode || 500)
  return reply.nextRender('/_error')
})

If you need to handle POST routes, you can define the HTTP method:

fastify.next('/api/*', { method: 'GET' });
fastify.next('/api/*', { method: 'POST' });

under-pressure

The plugin includes under-pressure, which can be configured by providing an underPressure property to the plugin options.

Using under-pressure allows implementing a circuit breaker which returns an error when the health metrics are not respected. Because React server side rendering is a blocking operation for the Node.js server, returning an error to the client allows signalling that the server is under too much load.

The available options are the same as those accepted by under-pressure.

For example:

fastify.register(require('fastify-nextjs'), { 
  underPressure: {
    exposeStatusRoute: true
  }
})
  • underPressure - bool|object

    • (default) when false, under-pressure is not registered
    • when true, under-pressure is registered with default options
    • when it is an object, under-pressure is registered with the provided options

Acknowledgements

This project is kindly sponsored by:

License

Licensed under MIT.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].