fix(rest/request_manager): pass authorization header instead (#534)

* fix big brain bot auth on proxy rest

* whoops

* fix header
This commit is contained in:
Skillz4Killz
2021-02-21 12:05:46 -05:00
committed by GitHub
parent 2d2af97957
commit d83665d8ff
2 changed files with 12 additions and 2 deletions

View File

@@ -10,6 +10,7 @@ import { baseEndpoints, GATEWAY_VERSION } from "./util/constants.ts";
import { spawnShards } from "./ws/shard_manager.ts";
export let authorization = "";
export let restAuthorization = "";
export let botID = "";
export let applicationID = "";
@@ -94,6 +95,7 @@ export async function startBigBrainBot(data: BigBrainBotConfig) {
authorization = `Bot ${data.token}`;
identifyPayload.token = `Bot ${data.token}`;
if (data.restAuthorization) restAuthorization = data.restAuthorization;
if (data.restURL) baseEndpoints.BASE_URL = data.restURL;
if (data.cdnURL) baseEndpoints.CDN_URL = data.cdnURL;
if (data.wsURL) proxyWSURL = data.wsURL;
@@ -133,4 +135,6 @@ export interface BigBrainBotConfig extends BotConfig {
restURL?: string;
/** This can be used to forward the CDN handling to a proxy. */
cdnURL?: string;
/** This is the authorization header that your rest proxy will validate */
restAuthorization?: string;
}

View File

@@ -1,4 +1,4 @@
import { authorization, eventHandlers } from "../bot.ts";
import { authorization, eventHandlers, restAuthorization } from "../bot.ts";
import {
Errors,
FileContent,
@@ -221,7 +221,13 @@ function runMethod(
!url.startsWith(`${BASE_URL}/v${API_VERSION}`) &&
!url.startsWith(IMAGE_BASE_URL)
) {
return fetch(url, { method, body: body ? JSON.stringify(body) : undefined })
return fetch(url, {
method,
body: body ? JSON.stringify(body) : undefined,
headers: {
authorization: restAuthorization,
},
})
.then((res) => res.json())
.catch((error) => {
console.error(error);