Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow disabling of server-proxy per route #287

Open
fago opened this issue Dec 31, 2024 · 1 comment · May be fixed by #288
Open

allow disabling of server-proxy per route #287

fago opened this issue Dec 31, 2024 · 1 comment · May be fixed by #288

Comments

@fago
Copy link
Contributor

fago commented Dec 31, 2024

For https://www.drupal.org/project/lupus_decoupled/issues/3487123#comment-15921123 we need to disable CSR and server-proxy for preview roues. CSR can be disabled via nuxt route rules, but the server-proxy feature is currently a global switch. We need to improve this to allow a per roue switch while it's generally on.

@fago
Copy link
Contributor Author

fago commented Dec 31, 2024

We could add our own setting or extend nuxt route rules with a new drupalApiProxy option.

// nuxt.config.ts
export default defineNuxtConfig({
  routeRules: {
    '/preview/**': { 
      ssr: false,
      drupalApiProxy: false
    }
  }
})

AI suggest to do it like this:

// module.ts
import type { RouteRules } from 'nitropack'

declare module 'nitropack' {
 interface RouteRules {
   drupalApiProxy?: boolean
 }
}

export default defineNuxtModule({
 setup(options, nuxt) {
   const processFetchOptions = (fetchOptions: UseFetchOptions<any> = {}) => {
     const route = useRoute()
     const routeRules = useRequestEvent()?.context?._nitro?.routeRules || {}
     const shouldUseProxy = routeRules.drupalApiProxy !== false

     if (config.serverApiProxy && shouldUseProxy) {
       fetchOptions.baseURL = '/api/drupal-ce'
     }
     else {
       fetchOptions.baseURL = fetchOptions.baseURL ?? getDrupalBaseUrl() + config.ceApiEndpoint
     }
     // rest of function
   }
 }
})

})

@fago fago linked a pull request Jan 4, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant