Skip to content

Commit

Permalink
refactor(proxyRequests): only take in a REST instance
Browse files Browse the repository at this point in the history
  • Loading branch information
didinele committed May 15, 2022
1 parent 2a76f3d commit 687ba1f
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions packages/proxy/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import type { IncomingMessage, ServerResponse } from 'http';
import { DiscordAPIError, RequestMethod, REST, RESTOptions, RouteLike } from '@discordjs/rest';
import { DiscordAPIError, RequestMethod, REST, RouteLike } from '@discordjs/rest';

type Awaitable<T> = T | PromiseLike<T>;
type RequestHandler = (req: IncomingMessage, res: ServerResponse) => Awaitable<void>;

export interface ProxyOptions extends RESTOptions {
token: string;
}

export const VALID_METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'];

// Should this actually support passing in an existing REST instance?
export function proxyRequests(options: REST | ProxyOptions): RequestHandler {
const rest = options instanceof REST ? options : new REST(options).setToken(options.token);
export function proxyRequests(rest: REST): RequestHandler {
return async (req, res) => {
// TODO: Parse the URL. REST always appends /api/v[version]
const { method, url } = req;
Expand Down

0 comments on commit 687ba1f

Please sign in to comment.