April 2016
Beginner
156 pages
3h 36m
English
inert (https://github.com/hapijs/inert) is the static file and directory handler module for hapi. It provides a lot of useful utilities for simplifying serving static content. Let's look at one of those now:
const Path = require('path');
const Hapi = require('hapi');
const Inert = require('inert'); // [1]
const server = new Hapi.Server();
server.connection({ port: 3000 });
server.register(Inert, (err) => { // [2]
server.route({
method: 'GET',
path: '/{param*}',
handler: { // [3]
directory: { // [3]
path: Path.join(__dirname, 'public'), // [3]
listing: true // [3]
} // [3]
} // [3]
});
server.start((err) => {
console.log(`Server running at: ${server.info.uri}`);
});
});Hopefully, this example is quite readable, and ...
Read now
Unlock full access