Skip to content

Commit

Permalink
feat(proxy): env var resolution (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
drochetti committed Jan 23, 2024
1 parent f5f22ef commit 12887d4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion libs/proxy/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fal-ai/serverless-proxy",
"version": "0.7.2",
"version": "0.7.3",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
12 changes: 7 additions & 5 deletions libs/proxy/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ export const TARGET_URL_HEADER = 'x-fal-target-url';

export const DEFAULT_PROXY_ROUTE = '/api/fal/proxy';

const FAL_KEY = process.env.FAL_KEY || process.env.NEXT_PUBLIC_FAL_KEY;
const FAL_KEY_ID = process.env.FAL_KEY_ID || process.env.NEXT_PUBLIC_FAL_KEY_ID;
const FAL_KEY_SECRET =
process.env.FAL_KEY_SECRET || process.env.NEXT_PUBLIC_FAL_KEY_SECRET;
const FAL_KEY = process.env.FAL_KEY;
const FAL_KEY_ID = process.env.FAL_KEY_ID;
const FAL_KEY_SECRET = process.env.FAL_KEY_SECRET;

export type HeaderValue = string | string[] | undefined | null;

Expand All @@ -24,6 +23,7 @@ export interface ProxyBehavior<ResponseType> {
getHeader(name: string): HeaderValue;
sendHeader(name: string, value: string): void;
getBody(): Promise<string | undefined>;
resolveApiKey?: () => Promise<string | undefined>;
}

/**
Expand Down Expand Up @@ -77,7 +77,9 @@ export async function handleRequest<ResponseType>(
return behavior.respondWith(412, `Invalid ${TARGET_URL_HEADER} header`);
}

const falKey = getFalKey();
const falKey = behavior.resolveApiKey
? await behavior.resolveApiKey()
: getFalKey();
if (!falKey) {
return behavior.respondWith(401, 'Missing fal.ai credentials');
}
Expand Down

0 comments on commit 12887d4

Please sign in to comment.