Skip to content

Latest commit

 

History

History
131 lines (105 loc) · 2.79 KB

README.md

File metadata and controls

131 lines (105 loc) · 2.79 KB

NPM Deps Tests Coverage Standard Code Style Chat

Hapi PostHTML

Install

npm i -S hapi-posthtml

Usage

import Hapi from 'hapi'

import vision from 'vision'
import posthtml from 'hapi-posthtml'

const server = new Hapi.Server()

// Create server
server.connection({
  host: 'localhost',
  port: 3000
})

// Vision for view support
server.register(vision, err => {
  if (err) {
    throw err
  }
  // PostHTML
  server.views({
    path: 'public/views/',
    engines: {
      'html': posthtml
    },
    relativeTo: __dirname,
    compileMode: 'async'
    compileOptions: {
      // PostHTML Plugins
      plugins: [/* Plugins */]
    }
  })
})

// Create route handlers
const handlers = {
  root: function (request, reply) {
    reply.view('index')
  },
  local: function (request, reply) {
    reply.view('index', { plugins: [/* Plugins */] })
  },
  extend: function (request, reply) {
    reply.view('index', { plugins: [/* Plugins */], extend: true})
  }
}

// Create routes
server.route({
  method: 'GET',
  path: '/',
  handler: handlers.root
})

server.route({
  method: 'GET',
  path: '/local',
  handler: handlers.local
})

server.route({
  method: 'GET',
  path: '/extend',
  handler: handlers.extend
})

server.start((err) => {
  if (err) {
    throw err
  }
  console.log('=> Server:', server.info.uri)
})

Maintainers


Michael Ciniawsky

Contributing

See PostHTML Guidelines and contribution guide.

LICENSE

MIT