@byu-oit/fastify-windrunner
v1.1.0
Published
Blazingly fast server development
Downloads
108
Maintainers
Keywords
Readme
@byu-oit/fastify-windrunner
Blazingly fast server development for BYU OIT
Usage
import Fastify from 'fastify'
import { Type } from '@fastify/type-provider-typebox'
import { ByuLogger } from '@byu-oit/logger'
import OpenApi from '@fastify/swagger'
import OpenApiUi from '@fastify/swagger-ui'
import ByuJwtProvider from '@byu-oit/fastify-jwt'
import { GroAuthorizationProvider } from '@byu-oit/windrunner-authorization-gro'
import { Field } from '@byu-oit/windrunner-contract'
import { PostgreSqlProvider } from '@byu-oit/windrunner-store-pg'
import { Windrunner } from '@byu-oit/fastify-windrunner'
/** Define the resource */
const byuId = Field.from(Type.String()).sortable(false)
const email = Field.from(Type.String())
const resource = { byuId, email }
/** Define options */
const prefix = '/example/v1'
const tableName = 'example'
const groupId = 'example'
/** Server setup */
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(ByuJwtProvider, { prefix, issuer: process.env.BYU_OIT_ISSUER, development: process.env.NODE_ENV !== 'production' })
fastify.register(GroAuthorizationProvider, { prefix, groupId })
const db = new PostgreSqlProvider({ tableName })
fastify.register(Windrunner, { prefix, resource, db })
await fastify.listen({ port: 3000 }).catch(err => {
console.error(err)
process.exit(1)
})