Supports Fastify versions 4.x
npm i gregdaynes/fastify-cms
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 })
npm run dev
# or
npm run example
npm run test
Licensed under The Unlicense.
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.
The schemas are provided by fluent-json-schema
, and can be extended
through the configuration object during plugin registration.
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
}
```
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 receivesid
The functiondocumentDelete
receives an extratimestamp
parameter with theid
,metadata
, anddata
Note If one
document*
override function is provided, all must be provided
A parsing function is exposed to allow customization of the parsing of the document.
```js
async function parseDocument (request, document) {
// do something
}
```