forked from krakenjs/kappa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kappa.js
executable file
·43 lines (33 loc) · 1.14 KB
/
kappa.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env node
var fs = require('fs'),
path = require('path'),
Hapi = require('hapi'),
argv = require('minimist')(process.argv.slice(2)),
shortstop = require('shortstop'),
handlers = require('shortstop-handlers');
function bomb(fn) {
return function setUsUpTheBomb(err) {
if (err) {
throw err;
}
return fn.apply(null, arguments);
};
}
var basedir, resolver, manifest, composer;
basedir = argv.b || argv.basedir;
basedir = basedir ? path.resolve(basedir) : process.cwd();
resolver = shortstop.create();
resolver.use('path', handlers.path(basedir));
resolver.use('file', handlers.file(basedir));
resolver.use('env', handlers.env(basedir));
manifest = require(path.resolve(basedir, argv.c || argv.config));
manifest = resolver.resolve(manifest);
composer = new Hapi.Composer(manifest);
composer.compose(bomb(function (err) {
composer.start(bomb(function (err) {
// This makes the baby Jesus weep.
composer._manifest[0].servers.forEach(function (server) {
console.log('Kappa listening on %s:%d', (server.host || ''), server.port);
});
}));
}));