Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: proxy lib exports #15

Merged
merged 2 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libs/proxy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ For Express applications:
```ts
app.use(express.json());
```
2. Add the proxy route and its handler. Note that if your client lives outside of the express app (i.e. the express app is solely used as an external API for other clients), your will need to allow CORS on the proxy route:
2. Add the proxy route and its handler. Note that if your client lives outside of the express app (i.e. the express app is solely used as an external API for other clients), you will need to allow CORS on the proxy route:

```ts
import * as falProxy from '@fal-ai/serverless-proxy/express';
Expand Down
14 changes: 13 additions & 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.3.0",
"version": "0.3.3",
"license": "MIT",
"repository": {
"type": "git",
Expand All @@ -21,6 +21,18 @@
"./express": "./src/express.js",
"./nextjs": "./src/nextjs.js"
},
"typesVersions": {
"*": {
"express": [
"src/express.d.ts"
],
"nextjs": [
"src/nextjs.d.ts"
]
}
},
"main": "./src/index.js",
"types": "./src/index.d.ts",
"peerDependencies": {
"express": "^4.0.0",
"next": "^13.0.0",
Expand Down
9 changes: 6 additions & 3 deletions libs/proxy/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ 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;

/**
* The proxy behavior that is passed to the proxy handler. This is a subset of
* request objects that are used by different frameworks, like Express and NextJS.
*/
export interface ProxyBehavior {
id: string;
method: string;
Expand Down Expand Up @@ -59,13 +63,12 @@ function getFalKey(): string | undefined {
}

/**
* A Next request handler that proxies the request to the fal-serverless
* A request handler that proxies the request to the fal-serverless
* endpoint. This is useful so client-side calls to the fal-serverless endpoint
* can be made without CORS issues and the correct credentials can be added
* effortlessly.
*
* @param request the Next request object.
* @param response the Next response object.
* @param behavior the request proxy behavior.
* @returns Promise<any> the promise that will be resolved once the request is done.
*/
export const handleRequest = async (behavior: ProxyBehavior) => {
Expand Down