Skip to content

Commit c6fabd0

Browse files
committed
fix custom responses
1 parent ecc5f02 commit c6fabd0

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

app/components/token/ResponseSettingsCard.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ const responseEnabled = ref(false)
8181
const responseStatus = ref('200')
8282
const responseHeadersText = ref('')
8383
const responseBody = ref('')
84+
const isFormInitialized = ref(false)
8485
8586
const statusSummary = computed(() => {
8687
const statusLabel = responseStatus.value?.trim().length ? responseStatus.value : '200'
@@ -119,14 +120,17 @@ const textToHeaders = (input: string): Record<string, string> | null => {
119120
return Object.keys(out).length ? out : null
120121
}
121122
122-
// Watch for token data changes and update form
123+
// Watch for token data changes and update form only on initial load
123124
watch(tokenData, (data) => {
124-
if (!data) return
125+
if (!data || isFormInitialized.value) {
126+
return
127+
}
125128
126129
responseEnabled.value = Boolean(data.responseEnabled)
127130
responseStatus.value = String(data.responseStatus ?? 200)
128131
responseHeadersText.value = headersToText(data.responseHeaders as Record<string, string> | null)
129132
responseBody.value = data.responseBody ?? ''
133+
isFormInitialized.value = true
130134
}, { immediate: true })
131135
132136
const handleToggleEnabled = async (enabled: boolean | 'indeterminate') => {

server/api/token/[token]/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ export default defineEventHandler(async (event: H3Event<EventHandlerRequest>) =>
3434
const payload = body as Record<string, unknown>
3535
const enabled = Boolean(payload.responseEnabled)
3636
const status = Number(payload.responseStatus ?? 200)
37-
const headers = (payload.responseHeaders as unknown) as Record<string, string> | null
37+
const headers = (payload.responseHeaders as unknown) as string | null
3838
const responseBody = (payload.responseBody as unknown) as string | null
3939

4040
await db.tokens.update(sessionId, tokenId, {
4141
responseEnabled: enabled,
4242
responseStatus: status,
43-
responseHeaders: headers ? JSON.stringify(headers) : null,
43+
responseHeaders: headers,
4444
responseBody,
4545
})
4646

0 commit comments

Comments
 (0)