-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve: LDP-2497: Add $ceApi helper and include query in server rout…
…es (#224) * improve: custom-fetch-instance: Add helper and include query in server routes * custom-fetch-instance: Add useCeApi helper * custom-fetch-instance: Improve code * custom-fetch-instance: Add dist * custom-fetch-instance: Remove query and add dist * custom-fetch-instance: Remove dist
- Loading branch information
Showing
2 changed files
with
55 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
import { defineEventHandler, proxyRequest, getRouterParams } from 'h3' | ||
import { defineEventHandler, proxyRequest, getRouterParams, getQuery } from 'h3' | ||
import { getDrupalBaseUrl } from '../../composables/useDrupalCe/server' | ||
import { useRuntimeConfig } from '#imports' | ||
|
||
export default defineEventHandler(async (event) => { | ||
const params = getRouterParams(event)._ | ||
const path = params ? '/' + params : '' | ||
const query = getQuery(event) ? '?' + new URLSearchParams(getQuery(event)) : '' | ||
const { ceApiEndpoint } = useRuntimeConfig().public.drupalCe | ||
// Remove x-forwarded-proto header as it causes issues with the request. | ||
delete event.req.headers['x-forwarded-proto'] | ||
return await proxyRequest(event, getDrupalBaseUrl() + ceApiEndpoint + path) | ||
return await proxyRequest(event, getDrupalBaseUrl() + ceApiEndpoint + path + query) | ||
}) |