Skip to content

Instantly share code, notes, and snippets.

@dbashford
Created August 13, 2014 00:19
Show Gist options
  • Save dbashford/9ae1268561e88cdbd883 to your computer and use it in GitHub Desktop.
Save dbashford/9ae1268561e88cdbd883 to your computer and use it in GitHub Desktop.
Hapi + Mimosa
var Hapi = require('hapi');
exports.startServer = function (config, callback) {
var port = process.env.PORT || config.server.port;
var serverOptions = {
views: {
path: config.server.views.path,
engines: {
dust: {
compileMode: 'async',
module: {
compile: function (template, options, next) {
var engine = require('dustjs-linkedin');
var compiled = engine.compileFn(template);
next(null, function (context, options, callback) {
return compiled(context, callback);
});
}
}
}
}
}
};
var server = new Hapi.Server('localhost', port, serverOptions);
var routeOptions = {
reload: config.liveReload.enabled,
optimize: ((config.isOptimize && config.isOptimize) ? true : false),
cachebust: ((process.env.NODE_ENV !== "production") ? "?b=#{(new Date()).getTime()}" : '')
};
// Default Route
server.route({
method: 'GET',
path: '/',
handler: function (req, reply) {
reply.view('index', routeOptions);
}
});
// Statically load public assets
server.route({
method: 'GET',
path: '/{param*}',
handler: {
directory: {
path: 'public'
}
}
});
server.start(function() {
console.log('Server running at:', server.info.uri);
});
callback(server.listener);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment