function getPage(pagePath, context) {
  try {
    const resolvedPage = resolvePagePath(pagePath, context.keys());
    const page = context(resolvedPage.page);

    return {
      ...resolvedPage,
      ...page,
    };
  } catch (e) {
    if (pagePath === "/_app") {
      return { default: App };
    }

    if (pagePath === "/_document") {
      return { default: Document };
    }

    throw new PageNotFoundError();
  }
}
If pagePath ends in /index trim it off (unless page is /index) to match router
returned pagePath for the same page