Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
fago committed Jan 4, 2025
1 parent 3119af9 commit fe92294
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
20 changes: 9 additions & 11 deletions src/runtime/composables/useDrupalCe/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const useDrupalCe = () => {
* @returns UseFetchOptions<any>
*/
const processFetchOptions = (fetchOptions: UseFetchOptions<any> = {}, skipDrupalCeApiProxy: boolean = false) => {
if (config.serverApiProxy && !skipDrupalCeApiProxy && routeRules.drupalCeApiProxy !== false) {
if (config.serverApiProxy && !skipDrupalCeApiProxy && useRoute().meta.drupalCeApiProxy !== false) {
fetchOptions.baseURL = '/api/drupal-ce'
}
else {
Expand Down Expand Up @@ -84,17 +84,13 @@ export const useDrupalCe = () => {

/**
* Returns the API endpoint with localization (if available)
* @param localize Whether to include localization in the endpoint
* @param skipDrupalCeApiProxy Force skip the Drupal CE API proxy. Defaults to false.
*/
const getCeApiEndpoint = (localize: boolean = true, skipDrupalCeApiProxy: boolean = false) => {
const getCeApiEndpoint = (localize: boolean = true) => {
const nuxtApp = useNuxtApp()
const fetchOptions = processFetchOptions({}, skipDrupalCeApiProxy)
const baseUrl = fetchOptions.baseURL
if (localize && nuxtApp.$i18n?.locale?.value && nuxtApp.$i18n.locale.value !== nuxtApp.$i18n.defaultLocale) {
return `${baseUrl}/${nuxtApp.$i18n.locale.value}`
return `${config.ceApiEndpoint}/${nuxtApp.$i18n.locale.value}`
}
return baseUrl
return config.ceApiEndpoint
}

/**
Expand Down Expand Up @@ -185,7 +181,9 @@ export const useDrupalCe = () => {
* @param skipDrupalCeApiProxy Force skip the Drupal CE API proxy. Defaults to false.
* The proxy might still be skipped if disabled globally or via route rules.
*/
const fetchMenu = async (name: string, useFetchOptions: UseFetchOptions<any> = {}, overrideErrorHandler?: (error?: any) => void, skipDrupalCeApiProxy: boolean = false) => { const nuxtApp = useNuxtApp()
const fetchMenu = async (name: string, useFetchOptions: UseFetchOptions<any> = {}, overrideErrorHandler?: (error?: any) => void, skipDrupalCeApiProxy: boolean = false) => {
const nuxtApp = useNuxtApp()
useFetchOptions = processFetchOptions(useFetchOptions)
useFetchOptions.key = `menu-${name}`
useFetchOptions.getCachedData = (key) => {
if (nuxtApp.payload.data[key]) {
Expand All @@ -208,8 +206,8 @@ export const useDrupalCe = () => {
menuPath.value = menuLocalePath
})
}
// @todo: Apply route rule and skipDrupalCeApiProxy
if (config.serverApiProxy) {

if (config.serverApiProxy && !skipDrupalCeApiProxy && useRoute().meta.drupalCeApiProxy !== false) {
useFetchOptions.baseURL = '/api/menu'
// menuPath should not start with a slash.
if (menuPath.value.startsWith('/')) {
Expand Down
4 changes: 0 additions & 4 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ declare module 'nitropack' {
}
}

export interface DrupalCeFetchOptions {
skipDrupalCeApiProxy?: boolean
}

export interface NuxtOptionsWithDrupalCe extends NuxtOptions {
drupalCe?: ModuleOptions
}

0 comments on commit fe92294

Please sign in to comment.