Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak README for gasket data #609

Merged
merged 2 commits into from
Jul 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions packages/gasket-data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@ import gasketData from '@gasket/data';
console.log(gasketData.something); // interesting
```

### Adding SSR Data
### Adding Data

To make data available for server-side rendering options, plugins should add to
the `res.locals.gasketData` object.

For example when using the [middleware lifecycle] in a plugin:
To add to the data exposed in `@gasket/data`, you can write to the HTTP response object's `locals.gasketData` property. For example when using the [middleware lifecycle] in a plugin:

```js
module.exports = {
Expand All @@ -48,8 +45,18 @@ module.exports = {
};
```

The results of `res.locals.gasketData` should then be rendering in a script as
described above.
The results of `res.locals.gasketData` should then be rendering in a script as described above. Similarly, this can be done in an application lifecycle script:

```js
// /lifecycles/middleware.js

module.exports = (gasket, app) => [
(req, res, next) => {
res.locals.gasketData ??= {};
res.locals.gasketData.example = gasket.config.somethingWeWantToExpose;
}
];
```

## License

Expand Down