npm

@byu-oit/fastify-windrunner
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

@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)
})

Readme

Keywords

none

Package Sidebar

Install

npm i @byu-oit/fastify-windrunner

Weekly Downloads

28

Version

1.1.0

License

Apache-2.0

Unpacked Size

43.9 kB

Total Files

23

Last publish

Collaborators

  • gholl0
  • mjweather
  • yoshutch
  • lehinpm
  • oscea
  • stuft2
  • mhailstone
  • arasmus8
  • garygsc
  • martingarn
  • snelg
  • byu-oit-bot