@requestly/requestly-proxy 1.3.6 → 1.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
const proxy_1 = require("../../../../lib/proxy");
|
|
7
4
|
const requestly_core_1 = require("@requestly/requestly-core");
|
|
8
5
|
const proxy_ctx_helper_1 = require("../../helpers/proxy_ctx_helper");
|
|
9
6
|
const utils_1 = require("../utils");
|
|
10
|
-
const fs_1 = __importDefault(require("fs"));
|
|
11
7
|
const http_helpers_1 = require("../../helpers/http_helpers");
|
|
12
8
|
const utils_2 = require("../../../../utils");
|
|
13
9
|
const constants_1 = require("../../constants");
|
|
@@ -17,16 +13,32 @@ const process_modify_response_action = async (action, ctx) => {
|
|
|
17
13
|
return (0, utils_1.build_action_processor_response)(action, false);
|
|
18
14
|
}
|
|
19
15
|
if (ctx.currentHandler === proxy_1.PROXY_HANDLER_TYPE.ON_REQUEST) {
|
|
20
|
-
if (action.
|
|
21
|
-
&& action.serveWithoutRequest) {
|
|
16
|
+
if (action.serveWithoutRequest) {
|
|
22
17
|
let contentType, finalBody;
|
|
18
|
+
if (action.responseType === requestly_core_1.CONSTANTS.RESPONSE_BODY_TYPES.LOCAL_FILE) {
|
|
19
|
+
try {
|
|
20
|
+
finalBody = (0, utils_1.get_file_contents)(action.response);
|
|
21
|
+
}
|
|
22
|
+
catch (err) {
|
|
23
|
+
console.log("Error reading file", err);
|
|
24
|
+
return (0, utils_1.build_action_processor_response)(action, false);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
else if (action.responseType === requestly_core_1.CONSTANTS.RESPONSE_BODY_TYPES.STATIC) {
|
|
28
|
+
finalBody = action.response;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
return (0, utils_1.build_action_processor_response)(action, false);
|
|
32
|
+
}
|
|
23
33
|
try {
|
|
24
|
-
|
|
34
|
+
const parsedResponse = JSON.parse(finalBody);
|
|
35
|
+
if (action.responseType === requestly_core_1.CONSTANTS.RESPONSE_BODY_TYPES.STATIC) {
|
|
36
|
+
finalBody = parsedResponse;
|
|
37
|
+
}
|
|
25
38
|
contentType = "application/json";
|
|
26
39
|
}
|
|
27
40
|
catch (_a) {
|
|
28
41
|
contentType = "text/plain";
|
|
29
|
-
finalBody = action.response;
|
|
30
42
|
}
|
|
31
43
|
const status = action.statusCode || 200;
|
|
32
44
|
const finalHeaders = { "Content-Type": contentType };
|
|
@@ -70,7 +82,7 @@ const modify_response = (ctx, new_resp, status_code) => {
|
|
|
70
82
|
const modify_response_using_local = (action, ctx) => {
|
|
71
83
|
let data;
|
|
72
84
|
try {
|
|
73
|
-
data =
|
|
85
|
+
data = (0, utils_1.get_file_contents)(action.response);
|
|
74
86
|
modify_response(ctx, data, action.statusCode);
|
|
75
87
|
}
|
|
76
88
|
catch (err) {
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.get_success_actions_from_action_results = exports.build_post_process_data = exports.build_action_processor_response = void 0;
|
|
6
|
+
exports.get_file_contents = exports.get_success_actions_from_action_results = exports.build_post_process_data = exports.build_action_processor_response = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
4
8
|
const build_action_processor_response = (action, success = false, post_process_data = null) => {
|
|
5
9
|
let resp = {
|
|
6
10
|
action: action,
|
|
@@ -31,3 +35,7 @@ const get_success_actions_from_action_results = (action_result_objs = []) => {
|
|
|
31
35
|
return success_action_results_objs.map((obj) => obj.action);
|
|
32
36
|
};
|
|
33
37
|
exports.get_success_actions_from_action_results = get_success_actions_from_action_results;
|
|
38
|
+
const get_file_contents = (file_path) => {
|
|
39
|
+
return fs_1.default.readFileSync(file_path, "utf-8");
|
|
40
|
+
};
|
|
41
|
+
exports.get_file_contents = get_file_contents;
|