1.0.0 • Published 8 years ago

hapi-express-routes v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

hapi-express-routes

Compatible with Hapi >=17.0.0

This Hapi plugin lets you add routes with an alternative Express-style API:

server.route.METHOD(PATH, HANDLER)

Where…

  • METHOD, is an HTTP request method, in lowercase
  • PATH is the value typically passed as the server.route option, path
  • HANDLER is the handler function (or options object) typically passed as the server.route option, handler

Example

// Express
app.get('/', (req, res) => {
  res.send('Hello, world!');
});

// Hapi (without plugin)
server.route({
  method: 'GET',
  path: '/',
  handler: async (request, h) => {
    return 'Hello, world!';
  }
});

// Hapi (with plugin)
server.route.get('/', async (request, h) => {
  return 'Hello, world!';
});

Additional Options

Each method also accepts a third parameter, options, which can be used to set the vhost or config options:

server.route.METHOD(PATH, HANDLER, {
  vhost: 'example.com',
  config: { … }
})
1.0.0

8 years ago