1 | exports.start = function(argv,process,os,httpServer,portfinder,opener,ports,hosts,root){
|
2 | var ifaces = os.networkInterfaces();
|
3 | var port = ports || parseInt(process.env.PORT, 9090),
|
4 | host = hosts || 'localhost',
|
5 | proxy = argv.P || argv.proxy;
|
6 |
|
7 |
|
8 |
|
9 | if (!port) {
|
10 | portfinder.basePort = 9090;
|
11 | portfinder.getPort(function (err, port) {
|
12 | if (err) { throw err; }
|
13 | listen(port);
|
14 | });
|
15 | }
|
16 | else {
|
17 | listen(port);
|
18 | }
|
19 |
|
20 | function listen(port) {
|
21 | var options = {
|
22 | root: root || './',
|
23 | |
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 | };
|
31 |
|
32 | if (argv.cors) {
|
33 | options.cors = true;
|
34 | }
|
35 |
|
36 |
|
37 |
|
38 | var server = httpServer.createServer(options);
|
39 |
|
40 | server.listen(port, host, function () {
|
41 | var canonicalHost = host === '0.0.0.0' ? '127.0.0.1' : host,
|
42 | protocol = 'http:';
|
43 |
|
44 |
|
45 | Object.keys(ifaces).forEach(function (dev) {
|
46 | ifaces[dev].forEach(function (details) {
|
47 | if (details.family === 'IPv4') {
|
48 |
|
49 | }
|
50 | });
|
51 |
|
52 | });
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | opener(
|
58 | protocol + '//' + canonicalHost + ':' + port,
|
59 | { command: argv.o !== true ? argv.o : null }
|
60 | );
|
61 |
|
62 | });
|
63 | }
|
64 |
|
65 | if (process.platform === 'win32') {
|
66 | require('readline').createInterface({
|
67 | input: process.stdin,
|
68 | output: process.stdout
|
69 | }).on('SIGINT', function () {
|
70 | process.emit('SIGINT');
|
71 | });
|
72 | }
|
73 |
|
74 |
|
75 | }
|
76 |
|
77 |
|