1.0.13 • Published 7 months ago

fastify-prerender-plugin v1.0.13

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

fastify-prerender-plugin

Have you ever had a SPA that renders some pages that need to be crawled by Google, Facebook, etc.? This Fastify plugin detects when the request is made from a bot using isbot and returns the HTML rendered by Playwright in that case.

Requirements

This plugin works best when Fastify serves the HTML page for the SPA.

Installation

To install the plugin, run:

pnpm install fastify-prerender-plugin

Usage

Here is an example of how to use the prerenderPlugin with Fastify:

import { fastify } from 'fastify'
import { prerenderPlugin } from '../src/prerender-plugin.ts'

const app = fastify()

await app.register(prerenderPlugin, {
  urls: ['/'],
  host: 'localhost',
  port: 3000
})

app.get('/', (request, reply) => {
  reply.type('text/html').send(`
<html>
  <body>
    <div id="root"></div>
  </body>
  <script>
    const root = document.getElementById('root')
    root.textContent = 'Hello World'
  </script>
</html>
  `)
})

app.listen({ port: 3000 })

Configuration

The prerenderPlugin accepts the following options:

  • urls: An array of strings or regular expressions representing the URLs to be prerendered.
  • host: The host where the Fastify server is running.
  • port: The port where the Fastify server is running.

Scripts

The following scripts are available in the package.json:

  • build: Builds the project using pkgroll.
  • postinstall: Installs the stable version of Chrome using Playwright.
  • release: Releases the project using release-it.
  • test: Runs the tests using Playwright.
  • format: Formats the code using Biome.

License

This project is licensed under the MIT License.

1.0.13

7 months ago

1.0.12

7 months ago

1.0.11

7 months ago

1.0.10

7 months ago

1.0.9

7 months ago

1.0.8

7 months ago

1.0.7

7 months ago

1.0.6

7 months ago

1.0.5

7 months ago

1.0.4

7 months ago

1.0.3

7 months ago

1.0.2

7 months ago

1.0.1

8 months ago

0.0.1

8 months ago

1.0.0

8 months ago