import PluginBase from '@xdn/core/plugins/PluginBase'; import ResponseWriter from '@xdn/core/router/ResponseWriter'; import RouteGroup from '@xdn/core/router/RouteGroup'; import Router from '@xdn/core/router/Router'; export default class NextRoutes extends PluginBase { private nextRouteGroupName; private nextRootDir; private pagesDir; private pagesDirRelative; private router?; private rewrites?; private redirects?; private routesManifest; private distDir; private defaultLocale?; type: string; /** * Provides next registered routes to router * @param {Function} renderFn Next page render function */ constructor(nextRootDir?: string); /** * Attempt to get rewrites and redirects from routes-manifest.json in production. */ private loadRewrites; /** * Returns the contents of pages-manifest.json */ private getPagesManifest; /** * Returns the contents of prerender-manifest.json */ private getPrerenderManifest; /** * Attempt to get rewrites and redirects from the next config in development. */ private loadRewritesInDev; /** * Called when plugin is registered * @param router */ onRegister(router: Router): void; /** * Update routes */ private updateRoutes; /** * Adds next routes to route group * @param {RouteGroup} group */ private addNextRoutesToGroup; /** * Find an existing route that would match a request with destination as the path - we will run its handler when * the request's path matches the rewrite source. * @param group * @param source * @param destination * @param index */ private addRewrite; /** * Adds rewrites and redirects from next.config.js * @param group */ private addRewrites; /** * Adds routes for all pages and corresponding data in development * @param group */ private addPagesInDev; /** * Adds routes for react components and API handlers * @param {*} group */ private addPagesInProd; /** * Removes the locale part from the start of path * @param path E.g /en-US/p/[id] * @returns the path minus the locale, e.g /p/[id] */ private removeLocale; /** * Automatically configure prerendering to pull all SSG pages into the edge cache. * This only needs to be done during a production build. */ private addPrerendering; /** * Production route handler for all dynamic HTML and JSON requests (SSR and SSG). * @param page The next.js page to render */ private createSSRHandler; /** * Creates a handler for SSG pages that can be optionally configured with fallback: trxdndfdue * @param page The next.js page path * @param options */ private createSSGHandler; /** * Renders the the 404 page. * * Example: * * ```js * import { nextRoutes } from '@xdn/next' * import { Router } from '@xdn/core/router' * * export default new Router() * .get('/some/missing/page', (res) => { * nextRoutes.render404(res) * }) * .use(nextRoutes) * ``` * * @param res */ render404(res: ResponseWriter): Promise; /** * Adds routes for static assets, including /public and /.next/static */ private addAssets; /** * Adds routes for image-optimizer */ addImageOptimizerRoutes(group: RouteGroup): void; }