lazy-compilation-node.js 928 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* global __resourceQuery */
  2. "use strict";
  3. var urlBase = decodeURIComponent(__resourceQuery.slice(1));
  4. exports.keepAlive = function (options) {
  5. var data = options.data;
  6. var onError = options.onError;
  7. var active = options.active;
  8. var module = options.module;
  9. var response;
  10. var request = (
  11. urlBase.startsWith("https") ? require("https") : require("http")
  12. ).request(
  13. urlBase + data,
  14. {
  15. agent: false,
  16. headers: { accept: "text/event-stream" }
  17. },
  18. function (res) {
  19. response = res;
  20. response.on("error", errorHandler);
  21. if (!active && !module.hot) {
  22. console.log(
  23. "Hot Module Replacement is not enabled. Waiting for process restart..."
  24. );
  25. }
  26. }
  27. );
  28. function errorHandler(err) {
  29. err.message =
  30. "Problem communicating active modules to the server: " + err.message;
  31. onError(err);
  32. }
  33. request.on("error", errorHandler);
  34. request.end();
  35. return function () {
  36. response.destroy();
  37. };
  38. };