How to use hostile - 10 common examples

To help you get started, we’ve selected a few hostile examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github JarvusInnovations / emergence / kernel-lib / sites.js View on Github external
return;
                }
            }

            // apply existing site's properties in
            _.defaults(requestData, me.sites[request.path[1]]);
        }

        // create new site
        try {
            cfgResult = me.writeSiteConfig(requestData);

            if (cfgResult.isNew) {
                // write primary hostname to /etc/hosts
                if (me.options.localhost) {
                    hostile.set(me.options.localhost, cfgResult.site.primary_hostname);
                    console.log('added ' + cfgResult.site.primary_hostname + ' to /etc/hosts');
                }

                // notify plugins
                me.emit('siteCreated', cfgResult.site, requestData, {
                    databaseReady: function () {
                        // execute onSiteCreated within site's container
                        console.log('Executing Site::onSiteCreated() via php-cli');
                        phpProc = spawn(phpShellScript, [cfgResult.site.handle]);

                        phpProc.stdout.on('data', function (data) { console.log('php-cli stdout: ' + data); });
                        phpProc.stderr.on('data', function (data) { console.log('php-cli stderr: ' + data); });

                        function _phpExec (code) {
                            //console.log('php> '+code);
                            phpProc.stdin.write(code+'\n');
github bbeldame / local.dev / index.js View on Github external
return new Promise((resolve) => {
    let ip = '';

    function filterFunc(line) {
      return !((Array.isArray(line) && line[1] === url) || (typeof line === 'string' && line.split(' ')[2] === this.port));
    }

    function hostileRemove(lines, port) {
      // Try to remove entry, if it exists
      const filteredLines = lines.filter(filterFunc, { port });
      return hostile.writeFile(filteredLines, () => {
        resolve(ip);
      });
    }

    hostile.get(true, (err, lines) => {
      if (err) error(err);
      let port = '';
      for (let i = 0; i < lines.length; i += 1) {
        if (typeof lines[i] === 'object' && lines[i][1] === url) {
          port = lines[i - 1].split(' ')[2];
          ip = lines[i][0];
        }
      }
      if (port === '') {
        error('This local.dev is not found');
      }
      return hostileRemove(lines, port);
    });
  });
}
github me-box / databox / src / sethosts.js View on Github external
p = p.then(() => new Promise((resolve, reject) => {
		// TODO: Are we sure they map to those IPs on Linux? Should precede with docker inspect?
		var ip = process.platform === 'linux' ? '172.17.0.' + (2 + i) : '127.0.0.1';
		hostile.set(ip, host, (err) => err ? reject(err) : resolve());
	}));
});
github bbeldame / local.dev / index.js View on Github external
function hostileRemove(lines, port) {
      // Try to remove entry, if it exists
      const filteredLines = lines.filter(filterFunc, { port });
      return hostile.writeFile(filteredLines, () => {
        resolve(ip);
      });
    }
github DylanPiercey / auto-sni / test / main.js View on Github external
ngrok.connect({ port: server.http.address().port }, function (err, url) {
        if (err) return t.fail(err)
        var host = url.replace('https://', '')

        hostile.set('127.0.0.1', host, function (err) {
          if (err) return t.fail(err)
          request(url + ':' + server.address().port)
            .get('/')
            .end(function (err, res) {
              if (err) return t.fail(err)
              t.equal(res.text, 'Hello World\n', 'should respond to https request')
              ngrok.disconnect(url)
              server.close()
              hostile.remove('127.0.0.1', host)
            })
        })
      })
    })
github DylanPiercey / auto-sni / test / main.js View on Github external
.end(function (err, res) {
              if (err) return t.fail(err)
              t.equal(res.text, 'Hello World\n', 'should respond to https request')
              ngrok.disconnect(url)
              server.close()
              hostile.remove('127.0.0.1', host)
            })
        })
github bbeldame / local.dev / index.js View on Github external
exports.list = function list() {
  hostile.get(true, (err, lines) => {
    if (err) {
      error(err);
    }

    for (let i = 0; i < lines.length; i += 1) {
      if (lines[i].slice(0, 11) === '# local.dev') {
        const port = lines[i].split(' ')[2];
        const url = lines[i + 1][1];
        console.log(`localhost:${chalk.green(`${port} <-`)} ${chalk.green(url)}`);
        i += 1;
      }
    }
  });
};
github bbeldame / local.dev / index.js View on Github external
activatePortForwarding(minIp, port).then(() => {
        hostile.set('# local.dev', port);
        hostile.set(minIp, url);
        console.log(chalk.green(`
Added local.dev :
localhost:${chalk.green(`${port} <-`)} ${chalk.green(url)}
        `));
      });
    });
github 10up / wp-local-docker-v2 / hosts.js View on Github external
const add = function( hosts ) {
    hostile.set( '127.0.0.1', hosts.join(' '), function( err ) {
        if (err) {
            console.error(err)
        } else {
            console.log('Added to hosts file successfully!')
        }
    });
};
github 10up / wp-local-docker-v2 / hosts.js View on Github external
const remove = function( hosts ) {
    hostile.remove( '127.0.0.1', hosts.join(' '), function( err ) {
        if (err) {
            console.error(err)
        } else {
            console.log('Removed from hosts file successfully!')
        }
    });
};

hostile

Simple /etc/hosts manipulation

MIT
Latest version published 10 months ago

Package Health Score

64 / 100
Full package analysis