Skip to content

Commit 1a7d673

Browse files
committed
feat: Do not proxy urls with loopback
1 parent 8fc9b44 commit 1a7d673

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

__tests__/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe("proxy", () => {
1313
const proxied = proxy("/image.png");
1414
expect(proxied).toEqual("/image.png");
1515
});
16-
test.each(["localhost", "LOCALhost", "0.0.0.0", "127.0.0.1", "0:0:0:0:0:0:0:1"])(
16+
test.each(["localhost", "LOCALhost", "0.0.0.0", "127.0.0.1", "0:0:0:0:0:0:0:1", "http://localhost:3000/image.png"])(
1717
"doesn't wrap loopback addresses: %s",
1818
(loopback) => {
1919
const proxied = proxy(loopback);

src/index.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ export const LOOPBACK_REGEX = new RegExp("^localhost$|^127(?:.[0-9]+){0,2}.[0-9]
3232
export function proxy(src: string): string {
3333
if (!src) return src;
3434
try {
35-
const isLoopback = LOOPBACK_REGEX.test(src);
36-
if (isLoopback) {
37-
return src;
38-
}
39-
4035
const isAbsolute = EXTERNAL_URL_REGEX.test(src);
4136
if (isAbsolute) {
4237
// Ensure protocol
@@ -45,6 +40,11 @@ export function proxy(src: string): string {
4540

4641
const url = new URL(src);
4742

43+
const isLoopback = LOOPBACK_REGEX.test(url.hostname);
44+
if (isLoopback) {
45+
return src;
46+
}
47+
4848
const isFlyyer = url.hostname === "cdn.flyyer.io";
4949

5050
// TODO: add list of CORS enabled services so proxy is not necessary.

0 commit comments

Comments
 (0)