Next.XP with Webpack -Backend

Enonic version: 7.11.0
OS: Win11

I started a new project with next.xp using nextjs-enonic-template v0.9.0 and webpack .-starter with com.enonic.lib:lib-guillotine:6.0.5 / com.enonic.lib:lib-nextjs:0.10.0.
I have a controller graphql.js based on the expample given in the docs here

I configured API in site.xml and can access it with localhost:8080/site/default/[draft/master]/lyn/graphql

I get the following error in my frontend:

Client-side error when trying to fetch data (path = "${site}/") Error: {"code":404,"message":"Data fetching failed (message: '{\"status\":404,\"message\":\"Page [/lyn/graphql] not found\"}')"}
    at fetchFromApi (webpack-internal:///./src/_enonicAdapter/guillotine/fetchContent.ts:39:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async fetchGuillotine (webpack-internal:///./src/_enonicAdapter/guillotine/fetchContent.ts:70:20)
    at async doRecursiveFetch (webpack-internal:///./src/pages/[[...contentPath]].tsx:98:20)
    at async getStaticPaths (webpack-internal:///./src/pages/[[...contentPath]].tsx:82:19)
    at async Object.buildStaticPaths (D:\Developement\enonic\nextjs-lyn\node_modules\next\dist\build\utils.js:597:33)
error - Error: Invalid `paths` value returned from getStaticPaths in /[[...contentPath]].
`paths` must be an array of strings or objects of shape { params: [key: string]: string }
    at Object.buildStaticPaths (D:\Developement\enonic\nextjs-lyn\node_modules\next\dist\build\utils.js:618:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  type: 'Error',
  page: '/[[...contentPath]]'
}

I see that /lyn/graphql is submitted as path! But I do not understand - why.
I also saw that in the demo-backend, GraphQL is also set up as a controller- but not included in site.xml

Is this now part of the lib-nextjs ?

Hi @luctho !

It seems that you have not published the root of your site.
This is done automatically in project we used in tutorial, but you will have to do it manually if you go for other ones.

Here is why it is needed now:
We use static rendering now and static pages use data from master branch.
And since static pages are built at the build time your master branch has to have data too.

You can do it manually simply by publishing the root site, or add a js snippet to your main.js controller as we did it in the demo app

Pavel

Hi @pmi . Unfortunately this is not the root cause. Root page is published !!

The message says that the Frontend wants to fetch page /lyn/graphQL instead od just /

/lyn/graphQL ist part of my endpoint!

Update: Found the root-cause :grinning: It was an permission issue. I granted read access to role: cms.everyone instead of system.everyone :rage:

Thomas

2 Likes