Skip to content

Commit 0f6dc56

Browse files
authored
RQLY-1042 feat: map local for redirect rule (#15)
1 parent 615bbbb commit 0f6dc56

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/components/proxy-middleware/rule_action_processor/handle_mixed_response.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const axios = require("axios");
22
const parser = require("ua-parser-js");
3+
import fs from "fs";
34
import * as Sentry from "@sentry/browser";
45

56
const handleMixedResponse = async (ctx, destinationUrl) => {
@@ -42,6 +43,34 @@ const handleMixedResponse = async (ctx, destinationUrl) => {
4243
}
4344
}
4445
}
46+
47+
if(destinationUrl?.startsWith("file://")) {
48+
const path = destinationUrl.slice(7)
49+
try {
50+
// utf-8 is common assumption, but this introduces edge cases
51+
const data = fs.readFileSync(path, "utf-8");
52+
return {
53+
status: true,
54+
response_data: {
55+
headers: { "Cache-Control": "no-cache" },
56+
status_code: 200,
57+
body: data,
58+
},
59+
};
60+
} catch (err) {
61+
Sentry.captureException(err);
62+
// log for live debugging
63+
console.log("error in openning local file", err)
64+
return {
65+
status: true,
66+
response_data: {
67+
headers: { "Cache-Control": "no-cache" },
68+
status_code: 502,
69+
body: err?.message,
70+
},
71+
};
72+
}
73+
}
4574
return { status: false };
4675
};
4776

src/components/proxy-middleware/rule_action_processor/processors/redirect_processor.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
build_action_processor_response,
1010
build_post_process_data,
1111
} from "../utils";
12-
const { URL } = require("url");
1312

1413
// adding util to get origin header for handling cors
1514
const getRequestOrigin = (ctx) => {

0 commit comments

Comments
 (0)