Skip to content

Commit

Permalink
fix: proxy lib exports (#15)
Browse files Browse the repository at this point in the history
* fix: update proxy package config

* fix: proxy lib exports at last
  • Loading branch information
drochetti committed Oct 8, 2023
1 parent b79e516 commit dcd513c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
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

0 comments on commit dcd513c

Please sign in to comment.