johannschopplich / nuxt-kql

🫧 Kirby's Query Language API for Nuxt
https://nuxt-kql.byjohann.dev
MIT License
42 stars 2 forks source link

Client-side only rendered application is calling for proxy KQL API #11

Closed sebastiantiede closed 1 year ago

sebastiantiede commented 1 year ago

Environment

Reproduction

nuxt.config.ts

export default defineNuxtConfig({
    ssr: false,
    pages: true,
    app: {
        // […]
    },
    css: [
        '~/assets/scss/app.scss'
    ],
    modules: ['nuxt-kql'],
    runtimeConfig: {
        // […]
    },
    kql: {
        auth: 'none',
        url: '[URL to Kirby],
        prefix: 'api/query',
        client: true
    }
})

Describe the bug

Dear Johann, thank you for this module!

The KQL (Kusto Query Language) query works flawlessly when running the application in nuxt dev mode – albeit through the proxy. However, the issue arises when attempting to access the KQL API in a static version of the application generated using nuxt generate. In this case, the application also tries to access the KQL API through the proxy interface, resulting in failure, since no proxy is provided.

Additional context

No response

Logs

No response

johannschopplich commented 1 year ago

Thanks for the flowers!

It seems you have set up the Nuxt config correctly. To fetch data directly from your Kirby instance, without the Nuxt proxy, set the option client to true as well. By default, each call will use the Nuxt proxy.

const { data } = await useKql(
  query,
  { client: true }
)

Side note: If you use SSG, it may be better to fetch all KQL queries at build time. If done so, no request needs to happen when the app is deployed.

sebastiantiede commented 1 year ago

Great! Thank you for your quick reply and help – this works. But - just to understand - shouldn't client: true under kql in the nuxt.config.ts serve the same purpose?

johannschopplich commented 1 year ago

Not at the moment, but would be a good API improvement probably…