Skip to content

gregdaynes/fastify-cms

Repository files navigation

Fastify CMS

js-standard-style CI workflow

Supports Fastify versions 4.x

Install

npm i gregdaynes/fastify-cms

Usage

Require fastify-cms and register.

import Fastify from 'fastify'
const fastify = Fastify()

fastify.register(import('fastify-cms'), {
  // put your options here
})

fastify.listen({ port: 3000 })

Development

npm run dev

# or

npm run example

Test

npm run test

Acknowledgements

License

Licensed under The Unlicense.

Documentation

Document

A document is the storage mechanism for a page, or some form of content that conforms to the Document schema.

ULID is used for generating ids for documents, which are sortable by creation time with a > b lexicographical sort.

The CMS is not intendend to handle a huge amount of documents, we can safely all documents metadata in memory.

Schema

The schemas are provided by fluent-json-schema, and can be extended through the configuration object during plugin registration.

Hook: Authenticate

Hooks for each API endpoint/method are exposed through the configuration object where the plugin is registered.

The authenticate* hooks are called on each request prior to the handler function.

authenticateCreate is called on POST / authenticateList is called on GET / authenticateRead is called on GET /:id authenticateUpdate is called on PUT /:id authenticateDelete is called on DELETE /:id

each of the authenticate* hooks have a signature that matches the Fastify hook api.

```js
async function authenticate (request, reply) {
  // do something
}
```

Document Store Functions

The document store functions are exposed through the configuration object where the plugin is registered.

The document* methods specific to each operation, follow the same API

```js
async function documentCreate (request, { id, metadata, data }, opts) {
  // do something
}
```

POST / calls documentCreate then documentRead on the new id GET / calls documentList GET /:id calls documentRead with the id parameter PUT /:id calls documentUpdate then documentRead with the id parameter DELETE /:id calls documentDelete with the id parameter

Note The function documentRead only receives id The function documentDelete receives an extra timestamp parameter with the id, metadata, and data

Note If one document* override function is provided, all must be provided

Document Parsing

A parsing function is exposed to allow customization of the parsing of the document.

```js
async function parseDocument (request, document) {
    // do something
}
```

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published