Files: ed26f7c5c655a65d700ecac4cddac76d22aad40a / features / support / hooks.js
1014 bytesRaw
1 | require('babel-core/register') |
2 | require('css-modules-require-hook') |
3 | |
4 | const _ = require('lodash') |
5 | const parallel = require('run-parallel') |
6 | |
7 | const config = require('app/config') |
8 | |
9 | module.exports = function () { |
10 | const servers = _.mapValues({ |
11 | static: require('app/static'), |
12 | api: require('app/api'), |
13 | render: require('app/render'), |
14 | proxy: require('app/proxy') |
15 | }, function (module) { |
16 | return module.createServer(config) |
17 | }) |
18 | |
19 | function start (cb) { |
20 | parallel( |
21 | _.map(servers, function (server, name) { |
22 | return function (callback) { |
23 | server.listen(config[name].port, callback) |
24 | } |
25 | }), |
26 | cb |
27 | ) |
28 | } |
29 | |
30 | function close (cb) { |
31 | parallel( |
32 | _.map(servers, function (server, name) { |
33 | return function (callback) { |
34 | server.close(callback) |
35 | } |
36 | }), |
37 | cb |
38 | ) |
39 | } |
40 | |
41 | this.registerHandler('BeforeFeatures', function (ev, cb) { |
42 | start(cb) |
43 | }) |
44 | |
45 | this.registerHandler('AfterFeatures', function (ev, cb) { |
46 | close(cb) |
47 | }) |
48 | } |
49 |
Built with git-ssb-web