fix: proxy content encoding header (#30)
This commit is contained in:
parent
a6624f4487
commit
c8ff2af189
@ -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';
|
||||
```
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
);
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@fal-ai/serverless-proxy",
|
||||
"version": "0.5.0",
|
||||
"version": "0.6.0",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@ -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),
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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,
|
||||
}),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user