-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
24,058 additions
and
14,404 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,31 @@ | ||
import type { RequestHandler } from 'express'; | ||
import { DEFAULT_PROXY_ROUTE, handleRequest } from './index'; | ||
|
||
/** | ||
* The default Express route for the fal.ai client proxy. | ||
*/ | ||
export const route = DEFAULT_PROXY_ROUTE; | ||
|
||
/** | ||
* The Express route handler for the fal.ai client proxy. | ||
* | ||
* @param request The Express request object. | ||
* @param response The Express response object. | ||
* @param next The Express next function. | ||
*/ | ||
export const handler: RequestHandler = async (request, response, next) => { | ||
handleRequest(request, response); | ||
await handleRequest({ | ||
id: 'express', | ||
method: request.method, | ||
respondWith: (status, data) => | ||
typeof data === 'string' | ||
? response.status(status).send(data) | ||
: response.status(status).json(data), | ||
getHeaders: () => request.headers, | ||
getHeader: (name) => request.headers[name], | ||
removeHeader: (name) => response.removeHeader(name), | ||
sendHeader: (name, value) => response.setHeader(name, value), | ||
getBody: () => JSON.stringify(request.body), | ||
}); | ||
next(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,30 @@ | ||
import type { NextApiHandler } from 'next/types'; | ||
import { DEFAULT_PROXY_ROUTE, handleRequest } from './index'; | ||
|
||
/** | ||
* The default Next API route for the fal.ai client proxy. | ||
*/ | ||
export const PROXY_ROUTE = DEFAULT_PROXY_ROUTE; | ||
|
||
/** | ||
* The Next API route handler for the fal.ai client proxy. | ||
* | ||
* @param request | ||
* @param response | ||
* @returns | ||
* @param request the Next API request object. | ||
* @param response the Next API response object. | ||
* @returns a promise that resolves when the request is handled. | ||
*/ | ||
export const handler: NextApiHandler = async (request, response) => { | ||
// TODO: right now we know the handleRequest function is relies on | ||
// properties that are common to both NextApiRequest and Request | ||
// but we should make sure that is the case by creating our own | ||
// interface as a contract for the minimal request/response properties | ||
// that handleRequest needs. | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
return handleRequest(request as any, response as any); | ||
return handleRequest({ | ||
id: 'nextjs', | ||
method: request.method, | ||
respondWith: (status, data) => | ||
typeof data === 'string' | ||
? response.status(status).send(data) | ||
: response.status(status).json(data), | ||
getHeaders: () => request.headers, | ||
getHeader: (name) => request.headers[name], | ||
removeHeader: (name) => response.removeHeader(name), | ||
sendHeader: (name, value) => response.setHeader(name, value), | ||
getBody: () => JSON.stringify(request.body), | ||
}); | ||
}; |
Oops, something went wrong.