# fastify-enhance-ssr

> Use [Enhance](https://enhance.dev)'s renderer as a view engine in a Fastify application.

Latest version **0.0.1-alpha.2** (published 2022-08-23) · 0 weekly downloads

## Install

```sh
npm install fastify-enhance-ssr
pnpm add fastify-enhance-ssr
yarn add fastify-enhance-ssr
bun add fastify-enhance-ssr
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1-alpha.2 |
| Published | 2022-08-23 |
| First published | 2022-07-29 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 2.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | tbeseda |
| Maintainers | tbeseda |
| Keywords | enhance, fastify |

## Links

- npm: https://www.npmjs.com/package/fastify-enhance-ssr
- Repository: https://github.com/tbeseda/fastify-enhance-ssr
- Issues: https://github.com/tbeseda/fastify-enhance-ssr/issues
- npm.io page: https://npm.io/package/fastify-enhance-ssr

## Dependencies (2)

- [@enhance/ssr](https://npm.io/package/@enhance/ssr.md) ^3.0.5
- [fastify-plugin](https://npm.io/package/fastify-plugin.md) ^4.2.0

## Recent versions

- 0.0.1-alpha.2 (latest) — 2022-08-23
- 0.0.1-alpha.1 (alpha) — 2022-07-29
- 0.0.1-alpha.0 — 2022-07-29

## README

# Fastify Server + Enhance SSR

Use [Enhance](https://enhance.dev)'s renderer as a view engine in a Fastify application.

> 💁  Not to be confused with `@enhance/fastify-plugin`, which offers the full Enhance stack in your Fastify app.

## Example

```js
import Fastify from 'fastify';
import enhanceSsr from 'fastify-enhance-ssr';
import HelloYou from './views/elements/hello-you.js';

const fastify = Fastify();

fastify.register(enhanceSsr, {
  enhanceOptions: {
    elements: { 'hello-you': HelloYou },
  },
});

fastify.get('/', async (_request, reply) => {
  const page = await import('./views/a-page.js');

  reply.enhance(page.default, {
    title: 'Enhance SSR on Fastify',
    user: { name: 'Enhanstify' },
  });
});

fastify.get('/simple', (_request, reply) => {
  reply.enhance('<hello-you></hello-you>');
});

fastify.listen();
```

Also see [`example/server.js`](./example/server.js) for further usage.

## Usage

`fastify-enhance-ssr` adds `reply.enhance`.

### `enhanceSsr` options

```ts
{
  layout: function(body: string, data: object): string,
  enhanceOptions: object,
}
```

### `reply.enhance(body, data, options)`

#### `body`

`string | function(data): string` a string of HTML or a function that returns a string of HTML. This will be passed to Enhance SSR.

#### `data`

`object` state provided to the body, layout, and Enhance (as `initialState`)

#### `options`

`{ layout: function }` override the default layout function

---
_Source: https://npm.io/package/fastify-enhance-ssr · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
