I followed this tutorial:
https://ghost.org/docs/jamstack/nuxt/
It only works when I set ssr = false
in the nuxt.config.ts
or use <ClientOnly><h1>{{ post.title }}</h1><ClientOnly>
If not, there an error message from AXIOS:
There is no suitable adapter to dispatch the request since :
- adapter xhr is not supported by the environment
- adapter http is not available in the build
Why does the GhostContentAPI only work on the client side?
I have discovered similar error messages
tryghost-content-api-is-not-working-on-next-v14
i-cant-use-local-ghost-content-api
But is not for NUXT.
Thanks for help, Joe
I have found a solution - using fetch instead of axios:
alyatwa , thank you.
just add data to return json
const api = new GhostContentAPI({
url: "https://ali-atwa.digitalpress.blog",
key: "bef5171833fd701e51903f181e",
// @ts-ignore
makeRequest: ({ url, method, params, headers }) => {
const apiUrl = new URL(url);
// @ts-ignore
Object.keys(params).map((key) =>
apiUrl.searchParams.set(key, encodeURIComponent(params[key]))
);
return fetch(apiUrl.toString(), { method, headers })
.then(async (res) => {
// Check if the response was successful.
if (…
The solution didn’t work perfect:
await ghostApi.pages
.browse({
limit: "all",
include: "tags,authors" <----- don't work
})
You have to remove encodeURIComponent
:
makeRequest: ({url, method, params, headers}) => {
const apiUrl = new URL(url);
Object.keys(params).map((key) =>
// apiUrl.searchParams.set(key, encodeURIComponent(params[key]))
apiUrl.searchParams.set(key, params[key])
);
...
And then it works