|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.4 KB
|
| Line | |
|---|
| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | /* global __resourceQuery */
|
|---|
| 4 |
|
|---|
| 5 | var urlBase = decodeURIComponent(__resourceQuery.slice(1));
|
|---|
| 6 |
|
|---|
| 7 | /**
|
|---|
| 8 | * @param {{ data: string, onError: (err: Error) => void, active: boolean, module: module }} options options
|
|---|
| 9 | * @returns {() => void} function to destroy response
|
|---|
| 10 | */
|
|---|
| 11 | exports.keepAlive = function (options) {
|
|---|
| 12 | var data = options.data;
|
|---|
| 13 |
|
|---|
| 14 | /**
|
|---|
| 15 | * @param {Error} err error
|
|---|
| 16 | */
|
|---|
| 17 | function errorHandler(err) {
|
|---|
| 18 | err.message =
|
|---|
| 19 | "Problem communicating active modules to the server: " + err.message;
|
|---|
| 20 | options.onError(err);
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 | /** @type {Promise<import("http") | import("https")>} */
|
|---|
| 24 | var mod = require("./load-http")(urlBase.startsWith("https"));
|
|---|
| 25 |
|
|---|
| 26 | /** @type {import("http").ClientRequest} */
|
|---|
| 27 | var request;
|
|---|
| 28 | /** @type {import("http").IncomingMessage} */
|
|---|
| 29 | var response;
|
|---|
| 30 |
|
|---|
| 31 | mod.then(function (client) {
|
|---|
| 32 | request = client.request(
|
|---|
| 33 | urlBase + data,
|
|---|
| 34 | {
|
|---|
| 35 | agent: false,
|
|---|
| 36 | headers: { accept: "text/event-stream" }
|
|---|
| 37 | },
|
|---|
| 38 | function (res) {
|
|---|
| 39 | response = res;
|
|---|
| 40 | response.on("error", errorHandler);
|
|---|
| 41 |
|
|---|
| 42 | if (!options.active && !options.module.hot) {
|
|---|
| 43 | console.log(
|
|---|
| 44 | "Hot Module Replacement is not enabled. Waiting for process restart..."
|
|---|
| 45 | );
|
|---|
| 46 | }
|
|---|
| 47 | }
|
|---|
| 48 | );
|
|---|
| 49 |
|
|---|
| 50 | request.on("error", errorHandler);
|
|---|
| 51 | request.end();
|
|---|
| 52 | });
|
|---|
| 53 |
|
|---|
| 54 | return function () {
|
|---|
| 55 | if (response) {
|
|---|
| 56 | response.destroy();
|
|---|
| 57 | }
|
|---|
| 58 | };
|
|---|
| 59 | };
|
|---|
| 60 |
|
|---|
| 61 | /**
|
|---|
| 62 | * @param {string} value new url value
|
|---|
| 63 | */
|
|---|
| 64 | exports.setUrl = function (value) {
|
|---|
| 65 | urlBase = value;
|
|---|
| 66 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.