Files: 9642105bd047078b96b5d68874a78e1c620077e2 / features / support / hooks.js
985 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 | }, function (module) { |
15 | return module.createServer(config) |
16 | }) |
17 | |
18 | function start (cb) { |
19 | parallel( |
20 | _.map(servers, function (server, name) { |
21 | return function (callback) { |
22 | server.listen(config[name].url.port, callback) |
23 | } |
24 | }), |
25 | cb |
26 | ) |
27 | } |
28 | |
29 | function close (cb) { |
30 | parallel( |
31 | _.map(servers, function (server, name) { |
32 | return function (callback) { |
33 | server.close(callback) |
34 | } |
35 | }), |
36 | cb |
37 | ) |
38 | } |
39 | |
40 | this.registerHandler('BeforeFeatures', function (ev, cb) { |
41 | start(cb) |
42 | }) |
43 | |
44 | this.registerHandler('AfterFeatures', function (ev, cb) { |
45 | close(cb) |
46 | }) |
47 | } |
48 |
Built with git-ssb-web