From 547df288a8de7217c73d4f99bb72bd32c4197378 Mon Sep 17 00:00:00 2001 From: Mats Johansen Date: Thu, 6 Jun 2024 09:22:37 +0200 Subject: [PATCH] feat(backend): add config for backend urls where ast is sent --- .../buttons/SearchButtonComponenet.wc.svelte | 20 +++++++++++++++++++ packages/lib/src/types/backend.ts | 5 +++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/packages/lib/src/components/buttons/SearchButtonComponenet.wc.svelte b/packages/lib/src/components/buttons/SearchButtonComponenet.wc.svelte index 0f4e257..88d21da 100644 --- a/packages/lib/src/components/buttons/SearchButtonComponenet.wc.svelte +++ b/packages/lib/src/components/buttons/SearchButtonComponenet.wc.svelte @@ -156,11 +156,31 @@ backend.send(cql, controller, measures); }); + options?.customAstBackends?.forEach((customAstBackendUrl: string) => { + customBackendCallWithAst(ast, customAstBackendUrl); + }); emitEvent(ast); queryModified.set(false); }; + const customBackendCallWithAst = (ast: AstTopLayer, url: string): void => { + fetch(url, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(ast), + }) + .then((response) => response.json()) + .then((data) => { + updateResponseStore(data); + }) + .catch((error) => { + console.error("Error:", error); + }); + }; + interface QueryEvent extends Event { detail: { ast: AstTopLayer; diff --git a/packages/lib/src/types/backend.ts b/packages/lib/src/types/backend.ts index d3817ba..cc439d6 100644 --- a/packages/lib/src/types/backend.ts +++ b/packages/lib/src/types/backend.ts @@ -75,8 +75,9 @@ export type BlazeOption = { }; export type BackendOptions = { - spots: SpotOption[]; - blazes: BlazeOption[]; + spots?: SpotOption[]; + blazes?: BlazeOption[]; + customAstBackends?: string[]; }; export interface QueryEvent extends Event {