command.reload.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. "use strict";
  2. /**
  3. * $ browser-sync reload <options>
  4. *
  5. * This commands starts the Browsersync servers
  6. * & Optionally UI.
  7. *
  8. * @param opts
  9. * @returns {Function}
  10. */
  11. module.exports = function (opts) {
  12. var flags = opts.cli.flags;
  13. if (!flags.url) {
  14. flags.url = "http://localhost:" + (flags.port || 3000);
  15. }
  16. var proto = require("../http-protocol");
  17. var scheme = flags.url.match(/^https/) ? "https" : "http";
  18. var args = { method: "reload" };
  19. if (flags.files) {
  20. args.args = flags.files;
  21. }
  22. var url = proto.getUrl(args, flags.url);
  23. if (scheme === "https") {
  24. process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
  25. }
  26. require(scheme)
  27. .get(url, function (res) {
  28. res.on("data", function () {
  29. if (res.statusCode === 200) {
  30. opts.cb(null, res);
  31. }
  32. });
  33. })
  34. .on("error", function (err) {
  35. if (err.code === "ECONNREFUSED") {
  36. err.message = "Browsersync not running at " + flags.url;
  37. }
  38. return opts.cb(err);
  39. });
  40. };
  41. //# sourceMappingURL=command.reload.js.map