I placed this code block in mars-theme/src/index.js within the mars-themeās before constant, so it is called in the beforeSSR action. Unfortunately, when loading the new products endpoint, I see a 404 error in the browser and in the terminal this error:
TypeError: Cannot destructure property id of āundefinedā or ānullā.
at attachmentHandler (webpack-internal:///./node_modules/@frontity/wp-source/src/libraries/handlers/attachment.ts:4:129)
at processTicksAndRejections (internal/process/task_queues.js:85:5)
at Object.postType [as func] (webpack-internal:///./node_modules/@frontity/wp-source/src/libraries/handlers/postType.ts:5:262)
at eval (webpack-internal:///./node_modules/@frontity/wp-source/src/actions.ts:13:100)
I have been able to get a small Create React App to list these CPTs no problem, so I know the REST API is open, and can see the JSON, but would love to better understand how Frontity works to get this working. Any help or tips hugely appreciated.
I see the error occurs inside the attachment handler. This means that you may have tried to fetch a link that doesnāt match the pattern of the product handler (/product/:slug), or for some reason the product handler hasnāt been added to libraries.source.handlers.
Whatās the content of window.frontity.libraries.source.handlers in the browser?
Ok, that means some error happenend while running the product handler (but at least it was executed).
The problem could be the endpoint used when calling libraries.source.api.get inside the handler. That endpoint should match the endpoint of your WP REST API, and in your case it seems to be product instead of products (the value we set in the example).
Hi @David, thanks yes I had already changed the endpoint value to singular product. Before then, when using the value as in the example, it was always returning 404. The 500 internal server error at least shows something is catching ā but itās not clear what is going on. At least to me itās not
Could you please share the code of your handler? Also, how are you dealing with it in your theme? Using something like data.isProduct? Or maybe put the whole repo in GitHub so we can take a look here
Oh, and handlers give you more flexibility, but support for custom post types and taxonomies with a simple wp-source setting is almost finished, I think. Right @david?
By the way, here you have an example of two handlers working fine:
I did the same thing for my handler, but I get an error. Looking at my network console, I see that frontity was looking at my rest-api-url/post?slug=dummy instead of rest-api-url/product?slug=dummy.
As āProductā is also a āPostTypeā, why this is happening?
Create custom pages and CPTās are the main work from a lot of WP developers. I believe itās very important to make this super clear at the docs. I struggled to create my custom page and add my CPT route at frontity. I believe that will be cool to have some CPT/CustomPage example code at the mars-theme.