Skip to content

Commit

Permalink
add-api-proxy: Add override examples and use serverDrupalBaseUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
vloss3 committed Dec 12, 2023
1 parent 82c5d53 commit c9feacf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ is added automatically to requests. Defaults to `false`.
- `useLocalizedMenuEndpoint`: If enabled, the menu endpoint will use a language prefix as configured by [nuxtjs/i18n](https://v8.i18n.nuxtjs.org) module. Defaults to `true`.

## Overriding options with environment variables
Runtime config values can be overriden with environment variables via `NUXT_PUBLIC_` prefix, e.g. `NUXT_PUBLIC_DRUPAL_BASE_URL`.
Runtime config values can be overriden with environment variables via `NUXT_PUBLIC_` prefix, example overrides:

- `drupalBaseUrl` -> `NUXT_PUBLIC_DRUPAL_CE_DRUPAL_BASE_URL`
- `serverDrupalBaseUrl` -> `NUXT_PUBLIC_DRUPAL_CE_SERVER_DRUPAL_BASE_URL`
- `menuBaseUrl` -> `NUXT_PUBLIC_DRUPAL_CE_MENU_BASE_URL`

## Deprecated options

Expand Down
3 changes: 2 additions & 1 deletion src/runtime/server/api/drupalCe.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export default defineEventHandler(async (event) => {
const path = `/${event.context.params._.replace('api/drupal-ce', '')}`
const drupalBaseUrl = useRuntimeConfig().public.drupalCe.baseURL
const drupalCe = useRuntimeConfig().public.drupalCe
const drupalBaseUrl = drupalCe.serverDrupalBaseUrl || drupalCe.baseURL
return await proxyRequest(event, drupalBaseUrl + path)
});
3 changes: 2 additions & 1 deletion src/runtime/server/api/menu.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export default defineEventHandler(async (event) => {
const menuBaseUrl = useRuntimeConfig().public.drupalCe.menuBaseUrl
const drupalCe = useRuntimeConfig().public.drupalCe
const menuBaseUrl = drupalCe.serverDrupalBaseUrl || drupalCe.menuBaseUrl
const menu = event.context.params._
return await proxyRequest(event, `${menuBaseUrl}/${menu}`, {
headers: {
Expand Down

0 comments on commit c9feacf

Please sign in to comment.