0.1.8 • Published 1 year ago

@byu-oit/fastify-bdp v0.1.8

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
1 year ago

Fastify BDP API Plugin

A fastify plugin to configure a BDP API

Installation

npm install @byu-oit/fastify-bdp

Usage Example

const Fastify = require('fastify')
const { Type } = require('@fastify/type-provider-typebox')
const { ByuLogger } = require('@byu-oit/logger')
const OpenApi = require('@fastify/swagger')
const OpenApiUi = require('@fastify/swagger-ui')
const { Modifier, BdpResource } = require('@byu-oit/bdp-api')

const byuId = {
    type: Type.String(),
    key: true,
    modifier: Modifier.READ_ONLY
}

const email = {
    type: Type.String(),
    modifier: Modifier.WRITABLE
}

const resource = { byuId, email }
const fastify = Fastify({ logger: ByuLogger() })

fastify.register(OpenApi, {
    swagger: {
        openapi: '3.1.0',
        info: {
            title: 'Example BDP API',
            version: '0.0.0'
        }
    }
})

fastify.register(OpenApiUi, {
    routePrefix: '/documentation'
})

fastify.register(BdpResource, { prefix: '/example/v1', resource, tableName: 'example' })

;(async () => {
    try {
        await fastify.listen({ port: 3000 })
    } catch (err) {
        fastify.log.error(err)
        process.exit(1)
    }
})()

/**
 * ByuJwt prevents SIGINT exit
 * Issue: https://github.com/byu-oit/byu-jwt-nodejs/issues/44
 */
process.on('SIGINT', () => process.exit())