Skip to content

Commit

Permalink
supplies custom fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitropoulos committed May 4, 2023
1 parent aa4b6c0 commit 6ddf8e3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion svelte/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import { createConnectTransport } from '@bufbuild/connect-web'
import { ElizaService } from '../gen/buf/connect/demo/eliza/v1/eliza_connect.js'
import { IntroduceRequest } from '../gen/buf/connect/demo/eliza/v1/eliza_pb.js'
import { wrapFetch } from './wrap-fetch.js';
export let data: { fetch: typeof fetch }
interface Response {
text: string
Expand All @@ -23,7 +26,8 @@
ElizaService,
createConnectTransport({
baseUrl: 'https://demo.connect.build',
})
fetch: wrapFetch('calling from connect', data.fetch),
}),
)
const send = async () => {
Expand Down
6 changes: 6 additions & 0 deletions svelte/src/routes/+page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { PageLoad } from './$types'
import { wrapFetch } from './wrap-fetch'

export const load: PageLoad = async ({ fetch }) => ({
fetch: wrapFetch('calling from +page.ts', fetch),
})
11 changes: 11 additions & 0 deletions svelte/src/routes/wrap-fetch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/** This utility helps to demonstrate that a custom implementation for fetch (first supplied by sveltekit then passed to Connect) is actually being called. */
export const wrapFetch = (
message: string,
fetch: typeof globalThis.fetch,
) => (
url: RequestInfo | URL,
init?: RequestInit | undefined,
) => {
console.log(message)
return fetch(url, init)
}

0 comments on commit 6ddf8e3

Please sign in to comment.