feat(config): Add support for HTTP proxies on outgoing requests

This commit is contained in:
Jesse Wierzbinski 2024-06-25 17:13:40 -10:00
parent 0ecb65de29
commit b8b822e553
No known key found for this signature in database
13 changed files with 225 additions and 136 deletions

View file

@ -1,6 +1,7 @@
import type { ServerMetadata } from "@lysand-org/federation/types";
import { db } from "~/drizzle/db";
import { Instances } from "~/drizzle/schema";
import { config } from "~/packages/config-manager";
/**
* Represents an instance in the database.
@ -24,9 +25,9 @@ export const addInstanceIfNotExists = async (url: string) => {
}
// Fetch the instance configuration
const metadata = (await fetch(new URL("/.well-known/lysand", origin)).then(
(res) => res.json(),
)) as ServerMetadata;
const metadata = (await fetch(new URL("/.well-known/lysand", origin), {
proxy: config.http.proxy.address,
}).then((res) => res.json())) as ServerMetadata;
if (metadata.type !== "ServerMetadata") {
throw new Error("Invalid instance metadata (wrong type)");

View file

@ -448,7 +448,9 @@ export const federateNote = async (note: Note) => {
);
// Send request
const response = await fetch(request);
const response = await fetch(request, {
proxy: config.http.proxy.address,
});
if (!response.ok) {
dualLogger.log(

View file

@ -175,7 +175,9 @@ export const followRequestUser = async (
);
// Send request
const response = await fetch(request);
const response = await fetch(request, {
proxy: config.http.proxy.address,
});
if (!response.ok) {
dualLogger.log(
@ -230,7 +232,9 @@ export const sendFollowAccept = async (follower: User, followee: User) => {
);
// Send request
const response = await fetch(request);
const response = await fetch(request, {
proxy: config.http.proxy.address,
});
if (!response.ok) {
dualLogger.log(
@ -258,7 +262,9 @@ export const sendFollowReject = async (follower: User, followee: User) => {
);
// Send request
const response = await fetch(request);
const response = await fetch(request, {
proxy: config.http.proxy.address,
});
if (!response.ok) {
dualLogger.log(
@ -375,6 +381,7 @@ export const resolveWebFinger = async (
headers: {
Accept: "application/json",
},
proxy: config.http.proxy.address,
},
);