diff --git a/web/src/actions/api/service.ts b/web/src/actions/api/service.ts index 58c4e5f..66470db 100644 --- a/web/src/actions/api/service.ts +++ b/web/src/actions/api/service.ts @@ -24,7 +24,7 @@ export const apiServiceActions = { .optional(), url: zodUrlOptionalProtocol.optional(), }), - handler: async (input) => { + handler: async (input, context) => { if (!input.id && !input.slug && !input.url) { throw new ActionError({ code: 'BAD_REQUEST', @@ -122,7 +122,7 @@ export const apiServiceActions = { (url) => url + (service.referral ?? '') ), tosUrls: service.tosUrls, - kycnotmeUrl: `https://kycnot.me/service/${service.slug}`, + kycnotmeUrl: new URL(`/service/${service.slug}`, context.url).href, } }, }), diff --git a/web/src/lib/makeAdminApiCallInfo.ts b/web/src/lib/makeAdminApiCallInfo.ts index 113aaf2..eb49594 100644 --- a/web/src/lib/makeAdminApiCallInfo.ts +++ b/web/src/lib/makeAdminApiCallInfo.ts @@ -13,15 +13,38 @@ export async function makeAdminApiCallInfo({ }) { const fullPath = new URL(`/api/v1${path}`, baseUrl).href + const fetchProsmise = fetch(fullPath, { + method, + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(input), + }).then((res) => { + try { + return res.json() as Promise + } catch (errJson: unknown) { + console.error(errJson) + + try { + return res.text() + } catch (errText: unknown) { + console.error(errText) + return '' + } + } + }) + + let output: Misc.JSON.Value = '' + try { + output = await fetchProsmise + } catch (err: unknown) { + console.error(err) + output = err instanceof Error ? err.message : String(err) + } + return { method, path, fullPath, input, - output: await fetch(fullPath, { - method, - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify(input), - }).then((res) => res.json() as Promise), + output, } } diff --git a/web/src/pages/admin/services/[slug]/edit.astro b/web/src/pages/admin/services/[slug]/edit.astro index ca53435..08b4cf3 100644 --- a/web/src/pages/admin/services/[slug]/edit.astro +++ b/web/src/pages/admin/services/[slug]/edit.astro @@ -2,6 +2,7 @@ import { Icon } from 'astro-icon/components' import { Markdown } from 'astro-remote' import { actions, isInputError } from 'astro:actions' +import { Code } from 'astro:components' import { orderBy } from 'lodash-es' import BadgeSmall from '../../../../components/BadgeSmall.astro' @@ -1121,16 +1122,10 @@ const apiCalls = await Astro.locals.banners.try( apiCalls.map((call) => (

Input:

-
+            
 
             

Output:

-
+            
           
         ))
       }