From 4aa1db3a03e888abb49d5dce9b87c9518eb5364b Mon Sep 17 00:00:00 2001 From: Pavel Jbanov Date: Wed, 10 Jul 2024 11:05:43 -0400 Subject: [PATCH] feat: added json parser options to startFlowsServer (#570) this just a cleanup of #193 Co-authored-by: tzahush --- js/flow/package.json | 3 ++- js/flow/src/flow.ts | 15 ++++++++------- js/pnpm-lock.yaml | 3 +++ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/js/flow/package.json b/js/flow/package.json index 7b2685ba6..24cbb3c6b 100644 --- a/js/flow/package.json +++ b/js/flow/package.json @@ -44,7 +44,8 @@ "npm-run-all": "^4.1.5", "tsup": "^8.0.2", "typescript": "^4.9.0", - "tsx": "^4.7.1" + "tsx": "^4.7.1", + "@types/body-parser": "^1.19.5" }, "files": [ "genkit-ui", diff --git a/js/flow/src/flow.ts b/js/flow/src/flow.ts index 6ecf061c3..8d318a1c3 100644 --- a/js/flow/src/flow.ts +++ b/js/flow/src/flow.ts @@ -16,28 +16,28 @@ import { Action, + defineAction, FlowError, FlowState, FlowStateSchema, FlowStateStore, - Operation, - StreamingCallback, - defineAction, getStreamingCallback, config as globalConfig, isDevEnv, + Operation, + StreamingCallback, } from '@genkit-ai/core'; import { logger } from '@genkit-ai/core/logging'; import { toJsonSchema } from '@genkit-ai/core/schema'; import { - SPAN_TYPE_ATTR, newTrace, setCustomMetadataAttribute, setCustomMetadataAttributes, + SPAN_TYPE_ATTR, } from '@genkit-ai/core/tracing'; import { SpanStatusCode } from '@opentelemetry/api'; import * as bodyParser from 'body-parser'; -import { CorsOptions, default as cors } from 'cors'; +import { default as cors, CorsOptions } from 'cors'; import express from 'express'; import { performance } from 'node:perf_hooks'; import * as z from 'zod'; @@ -45,9 +45,9 @@ import { Context } from './context.js'; import { FlowExecutionError, FlowStillRunningError, - InterruptError, getErrorMessage, getErrorStack, + InterruptError, } from './errors.js'; import * as telemetry from './telemetry.js'; import { @@ -844,12 +844,13 @@ export function startFlowsServer(params?: { port?: number; cors?: CorsOptions; pathPrefix?: string; + jsonParserOptions?: bodyParser.OptionsJson; }) { const port = params?.port || (process.env.PORT ? parseInt(process.env.PORT) : 0) || 3400; const pathPrefix = params?.pathPrefix ?? ''; const app = express(); - app.use(bodyParser.json()); + app.use(bodyParser.json(params?.jsonParserOptions)); app.use(cors(params?.cors)); const flows = params?.flows || createdFlows(); diff --git a/js/pnpm-lock.yaml b/js/pnpm-lock.yaml index 91d4368b4..4d436b8f0 100644 --- a/js/pnpm-lock.yaml +++ b/js/pnpm-lock.yaml @@ -146,6 +146,9 @@ importers: specifier: ^3.22.4 version: 3.22.4 devDependencies: + '@types/body-parser': + specifier: ^1.19.5 + version: 1.19.5 '@types/express': specifier: ^4.17.21 version: 4.17.21