@requestly/requestly-proxy 1.1.11 → 1.1.13

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.
@@ -31,9 +31,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
31
31
  step((generator = generator.apply(thisArg, _arguments || [])).next());
32
32
  });
33
33
  };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
34
37
  Object.defineProperty(exports, "__esModule", { value: true });
35
38
  const axios = require("axios");
36
39
  const parser = require("ua-parser-js");
40
+ const fs_1 = __importDefault(require("fs"));
37
41
  const Sentry = __importStar(require("@sentry/browser"));
38
42
  const handleMixedResponse = (ctx, destinationUrl) => __awaiter(void 0, void 0, void 0, function* () {
39
43
  var _a, _b, _c;
@@ -73,6 +77,34 @@ const handleMixedResponse = (ctx, destinationUrl) => __awaiter(void 0, void 0, v
73
77
  }
74
78
  }
75
79
  }
80
+ if (destinationUrl === null || destinationUrl === void 0 ? void 0 : destinationUrl.startsWith("file://")) {
81
+ const path = destinationUrl.slice(7);
82
+ try {
83
+ // utf-8 is common assumption, but this introduces edge cases
84
+ const data = fs_1.default.readFileSync(path, "utf-8");
85
+ return {
86
+ status: true,
87
+ response_data: {
88
+ headers: { "Cache-Control": "no-cache" },
89
+ status_code: 200,
90
+ body: data,
91
+ },
92
+ };
93
+ }
94
+ catch (err) {
95
+ Sentry.captureException(err);
96
+ // log for live debugging
97
+ console.log("error in openning local file", err);
98
+ return {
99
+ status: true,
100
+ response_data: {
101
+ headers: { "Cache-Control": "no-cache" },
102
+ status_code: 502,
103
+ body: err === null || err === void 0 ? void 0 : err.message,
104
+ },
105
+ };
106
+ }
107
+ }
76
108
  return { status: false };
77
109
  });
78
110
  exports.default = handleMixedResponse;
@@ -66,7 +66,7 @@ const modify_request_using_code = (action, ctx) => __awaiter(void 0, void 0, voi
66
66
  requestHeaders: ctx.clientToProxyRequest.headers,
67
67
  };
68
68
  try {
69
- args.requestJSON = JSON.parse(args.request);
69
+ args.bodyAsJson = JSON.parse(args.request);
70
70
  }
71
71
  catch (_a) {
72
72
  /*Do nothing -- could not parse body as JSON */
@@ -80,7 +80,7 @@ const modify_request_using_code = (action, ctx) => __awaiter(void 0, void 0, voi
80
80
  consoleCapture.stop();
81
81
  const consoleLogs = consoleCapture.getCaptures();
82
82
  ctx.rq.consoleLogs.push(...consoleLogs);
83
- const isRequestJSON = !!args.requestJSON;
83
+ const isRequestJSON = !!args.bodyAsJson;
84
84
  if (typeof finalRequest === "object" && isRequestJSON) {
85
85
  finalRequest = JSON.stringify(finalRequest);
86
86
  }
@@ -17,7 +17,6 @@ const proxy_ctx_helper_1 = require("../../helpers/proxy_ctx_helper");
17
17
  const modified_requests_pool_1 = __importDefault(require("../modified_requests_pool"));
18
18
  const handle_mixed_response_1 = __importDefault(require("../handle_mixed_response"));
19
19
  const utils_1 = require("../utils");
20
- const { URL } = require("url");
21
20
  // adding util to get origin header for handling cors
22
21
  const getRequestOrigin = (ctx) => {
23
22
  const originalRequestHeaders = ctx.rq.original_request.headers || {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@requestly/requestly-proxy",
3
- "version": "1.1.11",
3
+ "version": "1.1.13",
4
4
  "description": "Proxy that gives superpowers to all the Requestly clients",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {