我编写了一个节点应用程序,它使用多个端点从 API 获取数据。我也在使用代理来做到这一点。
我目前正在使用socks-proxy-agent为我的实例创建一个 https 代理axios来使用代理。
这是完成所有这些的类:
export class Checker {
private region: Region
private proxy: AxiosProxyConfig | false
private client: AxiosInstance
constructor(region: Region, proxy?: AxiosProxyConfig | false) {
this.region = region;
this.proxy = proxy;
if (proxy) {
const proxyOptions = `socks://${proxy.host}:${proxy.port}`;
const httpsAgent = new SocksProxyAgent(proxyOptions);
this.client = axios.create({ timeout: 5000, httpsAgent: httpsAgent });
} else {
this.client = axios.create({ timeout: 5000 });
}
}
public check(account: Account): Promise<CheckResponse> {
return new Promise((resolve, reject) => {
this.client.post("xxx", {
acr_values: "urn:riot:bronze",
claims: "",
client_id: "riot-client",
nonce: 1,
redirect_uri: "http://localhost/redirect",
response_type: "token id_token",
scope: "openid link ban lol_region",
}).then((response) => {
const cookies = response.headers["set-cookie"];
this.client.put(
"xxx",
{
type: "auth",
username: account.username,
password: account.password,
remember: false,
language: "en_GB",
region: this.region.login,
},
{
headers: {
Cookie: cookies,
},
}
)
陪伴而非守候
相关分类