Allow route for fetch only, not as public-facing browser url?

Hi,

trying to separate my overall problem (Holding page for CPT including posts of that CPT (eg /events)) into separate issues

I want to fetch content via eg fetch("/events-page") so I can insert that page’s content into another page (specifically my events archive), but I don’t want the user to be able to access mysite.com/events-page/ directly

if I add a handler to 404 the pattern /events-page/, then it also stops the fetch from working

thanks for any advice
J.

example here using test.frontity.org

in this case I want to disable the /about-us url but still be able to fetch data from that page in the backend (which you can see on the Destinations and Movies archive pages, I pull in the excerpt from about-us)

If you enable the aboutUsHandler at the bottom of the theme index.js, then it breaks these because 404’ing the main page also disables the fetch routes

I solved like this

beforeSSR: async ({ state, actions, libraries }) => {
  if(state.router.link === '/events-page/') {

    // manually 404 this route, ie when visiting mysite.com/events-page
    Object.assign(state.source.data[state.router.link], {
      isError: true,
      is404: true,
      isPostType: false,
      errorStatus: 404
    });
  }
  
  // fetch route still works
  if(state.router.link.startsWith('/events/')) {
    // grab the content from our dummy page
    await actions.source.fetch("/events-page/")
  }
1 Like