feat(client): allow custom fetch impl (#74)
* feat(client): allow custom fetch impl * fix(samples): remove test call * fix: proxy middleware order * chore(demo): switch to queue polling by default
This commit is contained in:
parent
cf300e9cc0
commit
2839e796db
@ -52,8 +52,9 @@ export default function Home() {
|
||||
const result: any = await fal.subscribe(endpointId, {
|
||||
input: JSON.parse(input),
|
||||
logs: true,
|
||||
mode: 'streaming',
|
||||
// pollInterval: 1000,
|
||||
// mode: "streaming",
|
||||
mode: 'polling',
|
||||
pollInterval: 1000,
|
||||
onQueueUpdate(update) {
|
||||
console.log('queue update');
|
||||
console.log(update);
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@fal-ai/serverless-client",
|
||||
"description": "The fal serverless JS/TS client",
|
||||
"version": "0.13.0",
|
||||
"version": "0.14.0-alpha.1",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@ -13,6 +13,7 @@ export type Config = {
|
||||
proxyUrl?: string;
|
||||
requestMiddleware?: RequestMiddleware;
|
||||
responseHandler?: ResponseHandler<any>;
|
||||
fetch?: typeof fetch;
|
||||
};
|
||||
|
||||
export type RequiredConfig = Required<Config>;
|
||||
@ -64,8 +65,8 @@ export function config(config: Config) {
|
||||
configuration = {
|
||||
...configuration,
|
||||
requestMiddleware: withMiddleware(
|
||||
configuration.requestMiddleware,
|
||||
withProxy({ targetUrl: config.proxyUrl })
|
||||
withProxy({ targetUrl: config.proxyUrl }),
|
||||
configuration.requestMiddleware
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
@ -14,6 +14,7 @@ export async function dispatchRequest<Input, Output>(
|
||||
credentials: credentialsValue,
|
||||
requestMiddleware,
|
||||
responseHandler,
|
||||
fetch = global.fetch,
|
||||
} = getConfig();
|
||||
const userAgent = isBrowser() ? {} : { 'User-Agent': getUserAgent() };
|
||||
const credentials =
|
||||
|
||||
@ -76,6 +76,7 @@ type KeyValuePair = [string, any];
|
||||
|
||||
export const storageImpl: StorageSupport = {
|
||||
upload: async (file: Blob) => {
|
||||
const { fetch = global.fetch } = getConfig();
|
||||
const { upload_url: uploadUrl, file_url: url } = await initiateUpload(file);
|
||||
const response = await fetch(uploadUrl, {
|
||||
method: 'PUT',
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import { createParser } from 'eventsource-parser';
|
||||
import { getTemporaryAuthToken } from './auth';
|
||||
import { getConfig } from './config';
|
||||
import { buildUrl } from './function';
|
||||
import { ApiError, defaultResponseHandler } from './response';
|
||||
import { storageImpl } from './storage';
|
||||
@ -83,6 +84,7 @@ export class FalStream<Input, Output> {
|
||||
private start = async () => {
|
||||
const { url, options } = this;
|
||||
const { input, method = 'post' } = options;
|
||||
const { fetch = global.fetch } = getConfig();
|
||||
try {
|
||||
const response = await fetch(url, {
|
||||
method: method.toUpperCase(),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user