11<script setup lang="ts">
22import JsonEditorVue from ' json-editor-vue'
33import { createReusableTemplate } from ' @vueuse/core'
4+ import type { $Fetch } from ' ofetch'
45import type { CodeSnippet , ServerRouteInfo , ServerRouteInput } from ' ~/../src/types'
56
67const props = defineProps <{
@@ -14,6 +15,7 @@ const emit = defineEmits<{
1415const [DefineDefaultInputs, UseDefaultInputs] = createReusableTemplate ()
1516
1617const config = useServerConfig ()
18+ const client = useClient ()
1719
1820const response = reactive ({
1921 contentType: ' text/plain' ,
@@ -67,7 +69,16 @@ const routeInputs = reactive({
6769 headers: [{ key: ' Content-Type' , value: ' application/json' , type: ' string' }] as ServerRouteInput [],
6870})
6971const routeInputBodyJSON = ref ({})
70- const { inputDefaults } = useDevToolsOptions (' serverRoutes' )
72+ const {
73+ inputDefaults,
74+ sendFrom,
75+ } = useDevToolsOptions (' serverRoutes' )
76+
77+ const resolvedSendFrom = computed (() => {
78+ if (! client ?.value ?.app ?.$fetch )
79+ return ' devtools'
80+ return sendFrom .value
81+ })
7182
7283const methods = [' GET' , ' POST' , ' PUT' , ' PATCH' , ' DELETE' , ' HEAD' ]
7384// https://github.com/unjs/h3/blob/main/src/utils/body.ts#L19
@@ -155,8 +166,12 @@ async function fetchData() {
155166
156167 const start = Date .now ()
157168
169+ const f = resolvedSendFrom .value === ' app'
170+ ? client .value ! .app ! .$fetch
171+ : $fetch as $Fetch
172+
158173 try {
159- response .data = await $fetch (finalURL .value , {
174+ response .data = await f (finalURL .value , {
160175 method: routeMethod .value .toUpperCase () as any ,
161176 headers: parsedHeader .value ,
162177 query: parsedQuery .value ,
@@ -298,14 +313,16 @@ const copy = useCopy()
298313 <div flex =" ~ col gap-2" flex-none p4 navbar-glass >
299314 <div flex =" ~ gap2 items-center" >
300315 <NButton
301- v-if =" route.method" class =" n-badge-base n-sm"
316+ v-if =" route.method"
317+ class =" n-badge-base n-sm"
302318 :class =" getRequestMethodClass(routeMethod)"
303319 pointer-events-none font-mono tabindex =" -1"
304320 >
305321 {{ routeMethod.toUpperCase() }}
306322 </NButton >
307323 <NSelect
308- v-else v-model =" routeMethod"
324+ v-else
325+ v-model =" routeMethod"
309326 class =" n-badge-base n-sm"
310327 :class =" getRequestMethodClass(routeMethod)"
311328 >
@@ -320,15 +337,24 @@ const copy = useCopy()
320337 p =" x5 y2"
321338 n =" sm"
322339 />
323- <NButton
324- v-tooltip =" 'Copy URL'"
325- title =" Copy URL"
326- absolute right-2 top-1.5
327- n =" xs blue"
328- icon =" carbon:copy"
329- :border =" false"
330- @click =" copy(finalURL)"
331- />
340+ <div absolute right-2 top-1.5 flex =" ~ gap-1" >
341+ <NButton
342+ v-tooltip =" 'Copy URL'"
343+ title =" Copy URL"
344+ n =" xs blue"
345+ icon =" carbon:copy"
346+ :border =" false"
347+ @click =" copy(finalURL)"
348+ />
349+ <NButton
350+ v-tooltip =" 'Open in Editor'"
351+ title =" Open in Editor"
352+ icon =" carbon-launch"
353+ n =" xs blue"
354+ :border =" false"
355+ @click =" openInEditor(route.filepath)"
356+ />
357+ </div >
332358 </div >
333359 <NButton n =" primary solid" @click =" fetchData" >
334360 <NIcon icon =" carbon:send" />
@@ -351,13 +377,21 @@ const copy = useCopy()
351377 </span >
352378 </NButton >
353379 <div flex-auto />
354- <NButton
355- v-tooltip =" 'Open in Editor'"
356- title =" Open in Editor"
357- @click =" openInEditor(route.filepath)"
380+ <div text-xs op50 >
381+ Send from
382+ </div >
383+ <NSelect
384+ v-model =" resolvedSendFrom"
385+ class =" n-xs"
386+ :disabled =" !client?.app?.$fetch"
358387 >
359- <NIcon icon =" carbon-launch" />
360- </NButton >
388+ <option value =" app" >
389+ App
390+ </option >
391+ <option value =" devtools" >
392+ DevTools
393+ </option >
394+ </NSelect >
361395 </div >
362396 <div
363397 v-if =" activeTab === 'params'"
0 commit comments