Skip to content

Commit c3b8d4c

Browse files
committed
chore: expose apiUrl
1 parent f28f955 commit c3b8d4c

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

apps/frontend/app/plugins/rpcApi.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@ export default defineNuxtPlugin({
99
name: 'local-rpcApi',
1010
parallel: true,
1111
async setup() {
12-
const url = useRequestURL()
13-
// If the frontend and backend domain are on the same domain, we will call the proxy instead of the backendUrl directly
12+
const requestUrl = useRequestURL()
1413
const backendUrl = useRuntimeConfig().public.backendUrl
1514
const urlBackend = new URL(backendUrl)
1615
const enableProxy = useAppConfig().enableProxy
16+
// `auto`: if the frontend and backend domain are on the same domain, we will call the proxy instead of the backendUrl directly
1717
const callProxy = enableProxy === 'auto'
18-
? urlBackend.hostname === url.hostname
18+
? urlBackend.hostname === requestUrl.hostname
1919
: enableProxy
20+
const apiUrl = callProxy
21+
? requestUrl.origin
22+
: backendUrl
2023

2124
// this wrappedFetch calculates the sha256 hash of the request body and adds it to the headers, it is necessary for AWS Lambda + OAC on POST/PUT requests.
2225
const wrappedFetch = async (url: string | URL | Request, options?: RequestInit) => {
@@ -40,12 +43,7 @@ export default defineNuxtPlugin({
4043
fetch: wrappedFetch,
4144
} satisfies ClientRequestOptions
4245

43-
const apiClient = hc<typeof app>(
44-
callProxy
45-
? `https://${url.host}`
46-
: backendUrl,
47-
clientRequestOptions,
48-
)
46+
const apiClient = hc<typeof app>(apiUrl, clientRequestOptions)
4947

5048
// Uncomment to include an Authorization header with the session token
5149
// await _withHeaderSession()
@@ -66,6 +64,7 @@ export default defineNuxtPlugin({
6664
return {
6765
provide: {
6866
apiClient,
67+
apiUrl,
6968
},
7069
}
7170
},

0 commit comments

Comments
 (0)