Exobase
  1. Root Hooks
  2. useNode

An Exobase root hook for a raw Node HTTP/S server

Install

yarn add @exobase/use-node

Import

import { useNode } from '@exobsae/use-node'

Usage

import https from 'https'
import { error } from '@exobase/core'
import { compose, toInt } from 'radash'
import { useRouter } from '@exobase/hooks'
import { useNode } from '@exobase/use-node'

const server = https.createServer(
  compose(
    useNode(),
    useRouter(router => router
      .on(['GET', 'POST'], '/ping', pingEndpoint)
      put('/v1/library/book/*/return', returnBookEndpoint),
      post('/v1/library/book', createBookEndpoint),
      get('/v1/library/book/*', findBookEndpoint),
      get('/v1/library/book', listBooksEndpoint),
    ),
    async () => {
      throw error({
        status: 404,
        message: 'Not found'
      })
    }
  )
)

const port = toInt(process.env.PORT, 8500)

server.listen(port, () => {
  console.log(`API listening on port ${port}`)
})