fix: proxy lib exports (#15)

* fix: update proxy package config

* fix: proxy lib exports at last
This commit is contained in:
Daniel Rochetti 2023-10-08 03:01:24 -07:00 committed by GitHub
parent b79e51683b
commit dcd513c1e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 5 deletions

View File

@ -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';

View File

@ -1,6 +1,6 @@
{
"name": "@fal-ai/serverless-proxy",
"version": "0.3.0",
"version": "0.3.3",
"license": "MIT",
"repository": {
"type": "git",
@ -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",

View File

@ -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;
@ -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) => {