0.1.1 • Published 7 years ago

hapi-nextjs v0.1.1

Weekly downloads
9
License
MIT
Repository
github
Last release
7 years ago

hapi-nextjs

npm standard

A nextjs plugin for hapi

This plugin provides an easy way to add a custom hapi server to a nextjs project.

NOTE: There are currently no tests for this plugin.

Table of Contents

Install

npm install hapi-nextjs

Usage

const Hapi = require('hapi')
const server = new Hapi.Server()

const dev = process.env.NODE_ENV !== 'production'
const port = parseInt(process.env.PORT || 3000, 10)

const nextPlugin = {
  register: require('hapi-nextjs')
  options: { dev }
}

server.connection({ port })
server.register(nextPlugin, (err) => {
  if (err) throw err

  server.start((err) => {
    if (err) throw err

    console.log(`> Ready on ${server.info.uri}`)
  })
})

Details

  • has a peerDependency on next >= 2, so bring your own next
  • binds a catch-all route, so add your custom routes/plugins before registering

Options

  • passes plugin options directly to next, in 2.x those options are:
    • dev (bool) whether to launch Next.js in dev mode - default false
    • dir (string) where the Next project is located - default '.'
    • quiet (bool) Hide error messages containing server information - default false

Contribute

PRs welcome! Please read the contributing guidelines and the code of conduct.

License

MIT © Jack Boberg.