Skip to content

Instantly share code, notes, and snippets.

@rahul8590
Created October 9, 2013 06:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rahul8590/6897018 to your computer and use it in GitHub Desktop.
Save rahul8590/6897018 to your computer and use it in GitHub Desktop.
Simple file handling structure using Hapijs . I am writing this out of pure frustration since, the website fails to cover the cases for static file handling.
var Hapi = require('hapi');
// Create a server with a host and port
var server = Hapi.createServer('localhost', 8000);
server.route([
{
method: 'GET',
path: '/{path*}',
handler: {
directory: { path: './public', listing: false, index: true }
}
},
//When you need to send mulitple files the handler should only incorporte the file parameter thats it. This is something which is //not obvious in the documentation.
{
method: 'GET',
path: '/about',
handler: { file: './public/about.html' }
}
]);
server.start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment