Created
October 9, 2013 06:24
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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