diff --git a/README.md b/README.md index 0309562..6c3faac 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ For example, if you are using Next.js, you can: ```sh npm install --save @fal-ai/serverless-proxy ``` -2. Add the proxy as an API endpoint of your app, see an example here in [pages/api/\_fal/proxy.ts](https://github.com/fal-ai/serverless-js/blob/main/apps/demo-nextjs-app/pages/api/_fal/proxy.ts) +2. Add the proxy as an API endpoint of your app, see an example here in [pages/api/\fal/proxy.ts](https://github.com/fal-ai/serverless-js/blob/main/apps/demo-nextjs-app/pages/api/fal/proxy.ts) ```ts export { handler as default } from '@fal-ai/serverless-proxy/nextjs'; ``` diff --git a/apps/demo-nextjs-page-router/pages/api/_fal/proxy.ts b/apps/demo-nextjs-page-router/pages/api/fal/proxy.ts similarity index 100% rename from apps/demo-nextjs-page-router/pages/api/_fal/proxy.ts rename to apps/demo-nextjs-page-router/pages/api/fal/proxy.ts diff --git a/apps/demo-nextjs-page-router/pages/index.tsx b/apps/demo-nextjs-page-router/pages/index.tsx index 7fb7994..0f121ab 100644 --- a/apps/demo-nextjs-page-router/pages/index.tsx +++ b/apps/demo-nextjs-page-router/pages/index.tsx @@ -4,8 +4,8 @@ import { useMemo, useState } from 'react'; // @snippet:start(client.config) fal.config({ requestMiddleware: fal.withProxy({ - targetUrl: '/api/_fal/proxy', // the built-int nextjs proxy - // targetUrl: 'http://localhost:3333/api/_fal/proxy', // or your own external proxy + targetUrl: '/api/fal/proxy', // the built-int nextjs proxy + // targetUrl: 'http://localhost:3333/api/fal/proxy', // or your own external proxy }), }); // @snippet:end diff --git a/libs/proxy/README.md b/libs/proxy/README.md index c626c3c..b4d7fcb 100644 --- a/libs/proxy/README.md +++ b/libs/proxy/README.md @@ -16,7 +16,7 @@ npm install --save @fal-ai/serverless-proxy For Next.js applications using the page router: -1. Create an API route in your Next.js app, as a convention we suggest using `pages/api/_fal/proxy.js` (or `.ts` if you're using TypeScript): +1. Create an API route in your Next.js app, as a convention we suggest using `pages/api/fal/proxy.js` (or `.ts` if you're using TypeScript): 2. Re-export the proxy handler from the library as the default export: ```ts export { handler as default } from '@fal-ai/serverless-proxy/nextjs'; @@ -52,7 +52,7 @@ For Express applications: import * as falProxy from '@fal-ai/serverless-proxy/express'; app.all( - falProxy.route, // '/api/_fal/proxy' or you can use your own + falProxy.route, // '/api/fal/proxy' or you can use your own cors(), // if external clients will use the proxy falProxy.handler ); diff --git a/libs/proxy/package.json b/libs/proxy/package.json index f2ea282..a03afdc 100644 --- a/libs/proxy/package.json +++ b/libs/proxy/package.json @@ -1,6 +1,6 @@ { "name": "@fal-ai/serverless-proxy", - "version": "0.5.0", + "version": "0.6.0", "license": "MIT", "repository": { "type": "git", diff --git a/libs/proxy/src/express.ts b/libs/proxy/src/express.ts index cb75777..5afb765 100644 --- a/libs/proxy/src/express.ts +++ b/libs/proxy/src/express.ts @@ -17,10 +17,7 @@ export const handler: RequestHandler = async (request, response, next) => { await handleRequest({ id: 'express', method: request.method, - respondWith: (status, data) => - typeof data === 'string' - ? response.status(status).json({ detail: data }) - : response.status(status).json(data), + respondWith: (status, data) => response.status(status).json(data), getHeaders: () => request.headers, getHeader: (name) => request.headers[name], sendHeader: (name, value) => response.setHeader(name, value), diff --git a/libs/proxy/src/index.ts b/libs/proxy/src/index.ts index d5d17d0..2902876 100644 --- a/libs/proxy/src/index.ts +++ b/libs/proxy/src/index.ts @@ -1,6 +1,6 @@ export const TARGET_URL_HEADER = 'x-fal-target-url'; -export const DEFAULT_PROXY_ROUTE = '/api/_fal/proxy'; +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; @@ -51,7 +51,7 @@ function getFalKey(): string | undefined { return undefined; } -const EXCLUDED_HEADERS = ['content-length']; +const EXCLUDED_HEADERS = ['content-length', 'content-encoding']; /** * A request handler that proxies the request to the fal-serverless diff --git a/libs/proxy/src/nextjs.ts b/libs/proxy/src/nextjs.ts index 2bb3d00..74680ae 100644 --- a/libs/proxy/src/nextjs.ts +++ b/libs/proxy/src/nextjs.ts @@ -19,10 +19,7 @@ export const handler: NextApiHandler = async (request, response) => { return handleRequest({ id: 'nextjs-page-router', method: request.method || 'POST', - respondWith: (status, data) => - typeof data === 'string' - ? response.status(status).json({ detail: data }) - : response.status(status).json(data), + respondWith: (status, data) => response.status(status).json(data), getHeaders: () => request.headers, getHeader: (name) => request.headers[name], sendHeader: (name, value) => response.setHeader(name, value), @@ -53,7 +50,7 @@ async function routeHandler(request: NextRequest) { id: 'nextjs-app-router', method: request.method, respondWith: (status, data) => - NextResponse.json(typeof data === 'string' ? { detail: data } : data, { + NextResponse.json(data, { status, headers: responseHeaders, }),