コード例 #1
0
ファイル: stdin.js プロジェクト: xat/castnow
var stdin = function(ctx, next) {
    debug(ctx.options.playlist);
    if (ctx.mode !== 'launch') return next();
    if (ctx.options.playlist.length != 1 || !isStdin(ctx.options.playlist[0])) return next();

    var port = ctx.options['stdin-port'] || 4104;
    var ip = ctx.options.myip || internalIp.v4.sync();
    ctx.options.playlist[0] = {
        path: 'http://' + ip + ':' + port,
        type: 'video/mp4'
    };

    http.createServer(function(req, res){
        process.stdin.pipe(res);
    }).listen(port);

    debug('started webserver for stdin on address %s using port %s', ip, port);
    next();

};
コード例 #2
0
ファイル: subtitles.js プロジェクト: xat/castnow
 srtToVtt(ctx.options, function(err, data) {
   if (err) return next();
   debug('loading subtitles', ctx.options.subtitles);
   if (err) return next();
   var ip = ctx.options.myip || internalIp.v4.sync();
   var addr = 'http://' + ip + ':' + port;
   http.createServer(function(req, res) {
     debug('incoming request');
     res.writeHead(200, {
       'Access-Control-Allow-Origin': '*',
       'Content-Length': data.length,
       'Content-type': 'text/vtt;charset=utf-8'
     });
     res.end(data);
   }).listen(port);
   debug('started webserver on address %s using port %s', ip, port);
   ctx.options.subtitles = addr;
   attachSubtitles(ctx);
   next();
 });
コード例 #3
0
ファイル: torrent.js プロジェクト: xat/castnow
 readTorrent(path, function(err, torrent) {
   if (err) {
     debug('error reading torrent: %o', err);
     return next();
   }
   if (!ctx.options['peerflix-port']) ctx.options['peerflix-port'] = port;
   var engine = peerflix(torrent, grabOpts(ctx.options, 'peerflix-'));
   var ip = ctx.options.myip || internalIp.v4.sync();
   engine.server.once('listening', function() {
     debug('started webserver on address %s using port %s', ip, engine.server.address().port);
     ctx.options.playlist[0] = {
       path: 'http://' + ip + ':' + engine.server.address().port,
       type: 'video/mp4',
       media: {
         metadata: {
           title: engine.server.index.name
         }
       }
     };
     next();
   });
 });
コード例 #4
0
ファイル: createDomain.js プロジェクト: Dans-labs/dariah
function createDomain(options, server) {
  const protocol = options.https ? 'https' : 'http';
  const hostname = options.useLocalIp
    ? ip.v4.sync() || 'localhost'
    : options.host;

  // eslint-disable-next-line no-nested-ternary
  const port = options.socket ? 0 : server ? server.address().port : 0;
  // use explicitly defined public url
  // (prefix with protocol if not explicitly given)
  if (options.public) {
    return /^[a-zA-Z]+:\/\//.test(options.public)
      ? `${options.public}`
      : `${protocol}://${options.public}`;
  }
  // the formatted domain (url without path) of the webpack server
  return url.format({
    protocol,
    hostname,
    port,
  });
}
コード例 #5
0
    alias: {
      '~': resolve(__dirname, 'src')
    }
  },

  performance: {
    hints: dev ? false : 'warning'
  }
}

if (dev) {
  module.exports.serve = {
    host: '0.0.0.0',
    hot: {
      host: {
        client: internalIp.v4.sync(),
        server: '0.0.0.0'
      }
    },
    port: config.serve.port,
    dev: {
      publicPath: config.publicPath
    },
    add: app => {
      app.use(convert(history({
        index: url.parse(config.publicPath).pathname,
        disableDotRule: true,
        htmlAcceptHeaders: ['text/html', 'application/xhtml+xml']
      })))
    }
  }
コード例 #6
0
);

// Reading args options
var prod = !!args.prod;
var lr = !args.nolr && !prod;
var watch = !args.nowatch && !prod;
var buffer = !args.stream;
var browser = !args.nobro && !prod;
var httpServer = !args.nosrv && !prod;
var req = !args.noreq || prod;

if (!prod) {
  // Finding the server IP
  conf.ip = args.ip
    ? 'auto' === args.ip
      ? internalIp.v4.sync()
      : args.ip
    : '127.0.0.1';
  conf.port = 9001;
  conf.baseURL = 'http://' + conf.ip + ':' + conf.port;
}
// Configure nunjuncks
Nunjucks.configure(conf.src.templates, {
  watch: watch,
  autoescape: true,
}).addFilter('date', function(date, lang) {
  return moment(date)
    .locale(lang)
    .format('LLLL');
});
コード例 #7
0
describe('check utility functions', () => {
  let compiler;
  let server;

  beforeAll(() => {
    compiler = webpack(config);
  });

  afterEach((done) => {
    server.close(() => {
      done();
    });
  });

  const tests = [
    {
      name: 'default',
      options: {
        host: 'localhost',
        port: 8080,
      },
      expected: 'http://localhost:8080',
    },
    {
      name: 'https',
      options: {
        host: 'localhost',
        port: 8080,
        https: true,
      },
      expected: 'https://localhost:8080',
      timeout: 60000,
    },
    {
      name: 'override with public',
      options: {
        host: 'localhost',
        port: 8080,
        public: 'myhost.test',
      },
      expected: 'http://myhost.test',
    },
    {
      name: 'override with public (port)',
      options: {
        host: 'localhost',
        port: 8080,
        public: 'myhost.test:9090',
      },
      expected: 'http://myhost.test:9090',
    },
    {
      name: 'override with public (protocol)',
      options: {
        host: 'localhost',
        port: 8080,
        public: 'https://myhost.test',
      },
      expected: 'https://myhost.test',
    },
    {
      name: 'override with public (protocol + port)',
      options: {
        host: 'localhost',
        port: 8080,
        public: 'https://myhost.test:9090',
      },
      expected: 'https://myhost.test:9090',
    },
    {
      name: 'localIp',
      options: {
        useLocalIp: true,
        port: 8080,
      },
      expected: `http://${internalIp.v4.sync() || 'localhost'}:8080`,
    },
  ];

  tests.forEach((test) => {
    it(`test createDomain '${test.name}'`, (done) => {
      const { options, expected } = test;

      server = new Server(compiler, options);

      server.listen(options.port, options.host, (err) => {
        if (err) {
          done(err);
        }

        const domain = createDomain(options, server.listeningApp);

        if (domain !== expected) {
          done(`generated domain ${domain} doesn't match expected ${expected}`);
        } else {
          done();
        }
      });
    });
  });
});
コード例 #8
0
ファイル: server.js プロジェクト: tushmesh/ecsdemo-nodejs
// use the express framework
var express = require('express');
var app = express();

var fs = require('fs');
var code_hash = fs.readFileSync('code_hash.txt','utf8');
console.log (code_hash);

// internal-ip: detect the correct IP based on default gw
var internalip = require('internal-ip');
var ipaddress = internalip.v4.sync();

// use ipaddress to find interface netmask
var ifaces = require('os').networkInterfaces();
for (var dev in ifaces) {
  // ... and find the one that matches the criteria
  var iface = ifaces[dev].filter(function(details) {
    return details.address === `${ipaddress}` && details.family === 'IPv4';
  });
  if(iface.length > 0) ifacenetmask = iface[0].netmask;
}

// ip: separate out the network using the subnet mask
var ipnet = require('ip');
var network = ipnet.mask(`${ipaddress}`, `${ifacenetmask}`)

// morgan: generate apache style logs to the console
var morgan = require('morgan')
app.use(morgan('combined'));

// express-healthcheck: respond on /health route for LB checks