From f064fd5a45c61822bbf8c06bb499be61e75bc789 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Tue, 1 Aug 2023 15:06:44 -0600 Subject: [PATCH] fix: remove route handlers --- .../js/src/entry/app/edge-route-bootstrap.ts | 13 ++-- .../next-core/js/src/entry/app/route.ts | 9 ++- .../js/src/internal/nodejs-proxy-handler.ts | 10 ++- .../crates/next-core/js/types/rust.d.ts | 18 ----- .../crates/next-core/src/bootstrap.rs | 38 +--------- packages/next/src/server/base-server.ts | 73 ++++++------------- .../next/src/server/dev/next-dev-server.ts | 3 +- .../route-handler-manager.ts | 42 ----------- .../future/route-matches/route-match.ts | 37 ---------- .../future/route-modules/app-page/module.ts | 4 - .../helpers/parsed-url-query-to-params.ts | 20 +++++ .../future/route-modules/app-route/module.ts | 5 +- .../future/route-modules/pages-api/module.ts | 4 - .../future/route-modules/pages/module.ts | 4 - .../future/route-modules/route-module.ts | 11 +-- .../server/web/edge-route-module-wrapper.ts | 15 ++-- 16 files changed, 77 insertions(+), 229 deletions(-) delete mode 100644 packages/next/src/server/future/route-handler-managers/route-handler-manager.ts create mode 100644 packages/next/src/server/future/route-modules/app-route/helpers/parsed-url-query-to-params.ts diff --git a/packages/next-swc/crates/next-core/js/src/entry/app/edge-route-bootstrap.ts b/packages/next-swc/crates/next-core/js/src/entry/app/edge-route-bootstrap.ts index 54193b75fa427..583f86b50d10f 100644 --- a/packages/next-swc/crates/next-core/js/src/entry/app/edge-route-bootstrap.ts +++ b/packages/next-swc/crates/next-core/js/src/entry/app/edge-route-bootstrap.ts @@ -1,15 +1,16 @@ import { EdgeRouteModuleWrapper } from 'next/dist/server/web/edge-route-module-wrapper' -import RouteModule from 'ROUTE_MODULE' +import { AppRouteRouteModule } from 'next/dist/server/future/route-modules/app-route/module' +import { RouteKind } from 'next/dist/server/future/route-kind' import * as userland from 'ENTRY' -import { PAGE, PATHNAME, KIND } from 'BOOTSTRAP_CONFIG' +import { PAGE, PATHNAME } from 'BOOTSTRAP_CONFIG' // TODO: (wyattjoh) - perform the option construction in Rust to allow other modules to accept different options -const routeModule = new RouteModule({ +const routeModule = new AppRouteRouteModule({ userland, definition: { + kind: RouteKind.APP_ROUTE, page: PAGE, - kind: KIND, pathname: PATHNAME, // The following aren't used in production. filename: '', @@ -22,6 +23,8 @@ const routeModule = new RouteModule({ // @ts-expect-error - exposed for edge support globalThis._ENTRIES = { middleware_edge: { - default: EdgeRouteModuleWrapper.wrap(routeModule, { page: `/${PAGE}` }), + default: EdgeRouteModuleWrapper.wrap(routeModule, { + page: `/${PAGE}`, + }), }, } diff --git a/packages/next-swc/crates/next-core/js/src/entry/app/route.ts b/packages/next-swc/crates/next-core/js/src/entry/app/route.ts index 9f268d1fe86e6..614581a7b0e8a 100644 --- a/packages/next-swc/crates/next-core/js/src/entry/app/route.ts +++ b/packages/next-swc/crates/next-core/js/src/entry/app/route.ts @@ -2,15 +2,16 @@ // the other imports import startHandler from '../../internal/nodejs-proxy-handler' -import RouteModule from 'ROUTE_MODULE' +import AppRouteRouteModule from 'next/dist/server/future/route-modules/app-route/module' +import { RouteKind } from 'next/dist/server/future/route-kind' import * as userland from 'ENTRY' -import { PAGE, PATHNAME, KIND } from 'BOOTSTRAP_CONFIG' +import { PAGE, PATHNAME } from 'BOOTSTRAP_CONFIG' -const routeModule = new RouteModule({ +const routeModule = new AppRouteRouteModule({ userland, definition: { + kind: RouteKind.APP_ROUTE, page: PAGE, - kind: KIND, pathname: PATHNAME, // The following aren't used in production. filename: '', diff --git a/packages/next-swc/crates/next-core/js/src/internal/nodejs-proxy-handler.ts b/packages/next-swc/crates/next-core/js/src/internal/nodejs-proxy-handler.ts index 873ddc77886f9..84a1e7d688352 100644 --- a/packages/next-swc/crates/next-core/js/src/internal/nodejs-proxy-handler.ts +++ b/packages/next-swc/crates/next-core/js/src/internal/nodejs-proxy-handler.ts @@ -15,13 +15,15 @@ import { NextRequestAdapter, signalFromNodeResponse, } from 'next/dist/server/web/spec-extension/adapters/next-request' -import { RouteHandlerManagerContext } from 'next/dist/server/future/route-handler-managers/route-handler-manager' import { attachRequestMeta } from './next-request-helpers' -import type { RouteModule } from 'next/dist/server/future/route-modules/route-module' +import type { + AppRouteRouteHandlerContext, + AppRouteRouteModule, +} from 'next/dist/server/future/route-modules/app-route/module' -export default (routeModule: RouteModule) => { +export default (routeModule: AppRouteRouteModule) => { startHandler(async ({ request, response, params }) => { const req = new NodeNextRequest(request) const res = new NodeNextResponse(response) @@ -29,7 +31,7 @@ export default (routeModule: RouteModule) => { const parsedUrl = parseUrl(req.url!, true) attachRequestMeta(req, parsedUrl, request.headers.host!) - const context: RouteHandlerManagerContext = { + const context: AppRouteRouteHandlerContext = { params, prerenderManifest: { version: -1 as any, // letting us know this doesn't conform to spec diff --git a/packages/next-swc/crates/next-core/js/types/rust.d.ts b/packages/next-swc/crates/next-core/js/types/rust.d.ts index 38fa2a1bbbfeb..87b0d190ce936 100644 --- a/packages/next-swc/crates/next-core/js/types/rust.d.ts +++ b/packages/next-swc/crates/next-core/js/types/rust.d.ts @@ -56,28 +56,10 @@ declare module 'ENTRY' { export = module } -declare module 'ROUTE_MODULE' { - import { - RouteModule, - type RouteModuleOptions, - } from 'next/dist/server/future/route-modules/route-module' - - /** - * This is the implementation class for the route module. This provides base - * typing for the options and context. - */ - export default class extends RouteModule { - constructor(options: O) - } -} - declare module 'BOOTSTRAP_CONFIG' { - import type { RouteKind } from 'next/dist/server/future/route-kind' - export const NAME: string export const PAGE: string export const PATHNAME: string - export const KIND: RouteKind } declare module 'APP_BOOTSTRAP' { diff --git a/packages/next-swc/crates/next-core/src/bootstrap.rs b/packages/next-swc/crates/next-core/src/bootstrap.rs index 2fc8ca3366213..ed33404956ed5 100644 --- a/packages/next-swc/crates/next-core/src/bootstrap.rs +++ b/packages/next-swc/crates/next-core/src/bootstrap.rs @@ -1,5 +1,5 @@ use anyhow::{bail, Result}; -use indexmap::{indexmap, IndexMap}; +use indexmap::IndexMap; use turbo_tasks::{Value, ValueToString, Vc}; use turbo_tasks_fs::{File, FileSystemPath}; use turbopack_binding::turbopack::{ @@ -7,14 +7,12 @@ use turbopack_binding::turbopack::{ asset::AssetContent, chunk::EvaluatableAsset, context::AssetContext, - issue::{IssueSeverity, OptionIssueSource}, module::Module, - reference_type::{EcmaScriptModulesReferenceSubType, InnerAssets, ReferenceType}, - resolve::parse::Request, + reference_type::{InnerAssets, ReferenceType}, source::Source, virtual_source::VirtualSource, }, - ecmascript::{resolve::esm_resolve, utils::StringifyJs, EcmascriptModuleAsset}, + ecmascript::utils::StringifyJs, }; #[turbo_tasks::function] @@ -25,39 +23,12 @@ pub async fn route_bootstrap( bootstrap_asset: Vc>, config: Vc, ) -> Result>> { - let resolve_origin = - if let Some(m) = Vc::try_resolve_downcast_type::(asset).await? { - Vc::upcast(m) - } else { - bail!("asset does not represent an ecmascript module"); - }; - - // TODO: this is where you'd switch the route kind to the one you need - let route_module_kind = "app-route"; - - let resolved_route_module = esm_resolve( - resolve_origin, - Request::parse_string(format!( - "next/dist/server/future/route-modules/{}/module", - route_module_kind - )), - Value::new(EcmaScriptModulesReferenceSubType::Undefined), - OptionIssueSource::none(), - IssueSeverity::Error.cell(), - ); - let route_module = match *resolved_route_module.first_module().await? { - Some(module) => module, - None => bail!("could not find app asset"), - }; - Ok(bootstrap( asset, context, base_path, bootstrap_asset, - Vc::cell(indexmap! { - "ROUTE_MODULE".to_string() => route_module, - }), + Vc::cell(IndexMap::new()), config, )) } @@ -105,7 +76,6 @@ pub async fn bootstrap( let mut config = config.await?.clone_value(); config.insert("PAGE".to_string(), path.to_string()); config.insert("PATHNAME".to_string(), pathname); - config.insert("KIND".to_string(), "APP_ROUTE".to_string()); let config_asset = context.process( Vc::upcast(VirtualSource::new( diff --git a/packages/next/src/server/base-server.ts b/packages/next/src/server/base-server.ts index 940c70c60bd48..354da3ee81aff 100644 --- a/packages/next/src/server/base-server.ts +++ b/packages/next/src/server/base-server.ts @@ -28,10 +28,12 @@ import type { NextFontManifest } from '../build/webpack/plugins/next-font-manife import type { PagesRouteModule } from './future/route-modules/pages/module' import type { AppPageRouteModule } from './future/route-modules/app-page/module' import type { NodeNextRequest, NodeNextResponse } from './base-http/node' -import type { AppRouteRouteMatch } from './future/route-matches/app-route-route-match' -import type { RouteDefinition } from './future/route-definitions/route-definition' import type { WebNextRequest, WebNextResponse } from './base-http/web' import type { PagesAPIRouteMatch } from './future/route-matches/pages-api-route-match' +import type { + AppRouteRouteHandlerContext, + AppRouteRouteModule, +} from './future/route-modules/app-route/module' import { format as formatUrl, parse as parseUrl } from 'url' import { getRedirectStatus } from '../lib/redirect-status' @@ -88,10 +90,6 @@ import { MatchOptions, RouteMatcherManager, } from './future/route-matcher-managers/route-matcher-manager' -import { - RouteHandlerManager, - type RouteHandlerManagerContext, -} from './future/route-handler-managers/route-handler-manager' import { LocaleRouteNormalizer } from './future/normalizers/locale-route-normalizer' import { DefaultRouteMatcherManager } from './future/route-matcher-managers/default-route-matcher-manager' import { AppPageRouteMatcherProvider } from './future/route-matcher-providers/app-page-route-matcher-provider' @@ -110,13 +108,11 @@ import { toNodeOutgoingHttpHeaders, } from './web/utils' import { NEXT_QUERY_PARAM_PREFIX } from '../lib/constants' -import { - isRouteMatch, - parsedUrlQueryToParams, - type RouteMatch, -} from './future/route-matches/route-match' import { normalizeLocalePath } from '../shared/lib/i18n/normalize-locale-path' -import { signalFromNodeResponse } from './web/spec-extension/adapters/next-request' +import { + NextRequestAdapter, + signalFromNodeResponse, +} from './web/spec-extension/adapters/next-request' export type FindComponentsResult = { components: LoadComponentsReturnType @@ -343,7 +339,6 @@ export default abstract class Server { // TODO-APP: (wyattjoh): Make protected again. Used for turbopack in route-resolver.ts right now. public readonly matchers: RouteMatcherManager - protected readonly handlers: RouteHandlerManager protected readonly i18nProvider?: I18NProvider protected readonly localeNormalizer?: LocaleRouteNormalizer protected readonly isRenderWorker?: boolean @@ -462,9 +457,8 @@ export default abstract class Server { this.appPathRoutes = this.getAppPathRoutes() // Configure the routes. - const { matchers, handlers } = this.getRoutes() + const { matchers } = this.getRoutes() this.matchers = matchers - this.handlers = handlers // Start route compilation. We don't wait for the routes to finish loading // because we use the `waitTillReady` promise below in `handleRequest` to @@ -508,7 +502,6 @@ export default abstract class Server { protected getRoutes(): { matchers: RouteMatcherManager - handlers: RouteHandlerManager } { // Create a new manifest loader that get's the manifests from the server. const manifestLoader = new ServerManifestLoader((name) => { @@ -524,7 +517,6 @@ export default abstract class Server { // Configure the matchers and handlers. const matchers: RouteMatcherManager = new DefaultRouteMatcherManager() - const handlers = new RouteHandlerManager() // Match pages under `pages/`. matchers.push( @@ -555,7 +547,7 @@ export default abstract class Server { ) } - return { matchers, handlers } + return { matchers } } public logError(err: Error): void { @@ -1806,27 +1798,11 @@ export default abstract class Server { // served by the server. let result: RenderResult - // Get the match for the page if it exists. - const match: RouteMatch> | undefined = - getRequestMeta(req, '_nextMatch') ?? - // If the match can't be found, rely on the loaded route module. This - // should only be required during development when we add FS routes. - ((this.renderOpts.dev || process.env.NEXT_RUNTIME === 'edge') && - components.routeModule - ? { - definition: components.routeModule.definition, - params: opts.params - ? parsedUrlQueryToParams(opts.params) - : undefined, - } - : undefined) + if (components.routeModule?.definition.kind === RouteKind.APP_ROUTE) { + const routeModule = components.routeModule as AppRouteRouteModule - if ( - match && - isRouteMatch(match, RouteKind.APP_ROUTE) - ) { - const context: RouteHandlerManagerContext = { - params: match.params, + const context: AppRouteRouteHandlerContext = { + params: opts.params, prerenderManifest: this.getPrerenderManifest(), staticGenerationContext: { originalPathname: components.ComponentMod.originalPathname, @@ -1837,14 +1813,13 @@ export default abstract class Server { } try { - // Handle the match and collect the response if it's a static response. - const response = await this.handlers.handle( - match, + const request = NextRequestAdapter.fromBaseNextRequest( req, - context, signalFromNodeResponse((res as NodeNextResponse).originalResponse) ) + const response = await routeModule.handle(request, context) + ;(req as any).fetchMetrics = ( context.staticGenerationContext as any ).fetchMetrics @@ -1903,11 +1878,7 @@ export default abstract class Server { // If we've matched a page while not in edge where the module exports a // `routeModule`, then we should be able to render it using the provided // `render` method. - else if ( - match && - isRouteMatch(match, RouteKind.PAGES) && - components.routeModule - ) { + else if (components.routeModule?.definition.kind === RouteKind.PAGES) { const module = components.routeModule as PagesRouteModule // Due to the way we pass data by mutating `renderOpts`, we can't extend @@ -1922,12 +1893,10 @@ export default abstract class Server { (req as NodeNextRequest).originalRequest ?? (req as WebNextRequest), (res as NodeNextResponse).originalResponse ?? (res as WebNextResponse), - { page: pathname, params: match.params, query, renderOpts } + { page: pathname, params: opts.params, query, renderOpts } ) } else if ( - match && - isRouteMatch(match, RouteKind.APP_PAGE) && - components.routeModule + components.routeModule?.definition.kind === RouteKind.APP_PAGE ) { const module = components.routeModule as AppPageRouteModule @@ -1941,7 +1910,7 @@ export default abstract class Server { (req as NodeNextRequest).originalRequest ?? (req as WebNextRequest), (res as NodeNextResponse).originalResponse ?? (res as WebNextResponse), - { page: pathname, params: match.params, query, renderOpts } + { page: pathname, params: opts.params, query, renderOpts } ) } else { // If we didn't match a page, we should fallback to using the legacy diff --git a/packages/next/src/server/dev/next-dev-server.ts b/packages/next/src/server/dev/next-dev-server.ts index 80ae75f5a9b47..b003c1b93e4c9 100644 --- a/packages/next/src/server/dev/next-dev-server.ts +++ b/packages/next/src/server/dev/next-dev-server.ts @@ -208,7 +208,6 @@ export default class DevServer extends Server { ensurer, this.dir ) - const handlers = routes.handlers const extensions = this.nextConfig.pageExtensions const fileReader = new CachedFileReader(new DefaultFileReader()) @@ -241,7 +240,7 @@ export default class DevServer extends Server { ) } - return { matchers, handlers } + return { matchers } } protected getBuildId(): string { diff --git a/packages/next/src/server/future/route-handler-managers/route-handler-manager.ts b/packages/next/src/server/future/route-handler-managers/route-handler-manager.ts deleted file mode 100644 index 011df25738a2f..0000000000000 --- a/packages/next/src/server/future/route-handler-managers/route-handler-manager.ts +++ /dev/null @@ -1,42 +0,0 @@ -import type { BaseNextRequest } from '../../base-http' -import type { ModuleLoader } from '../helpers/module-loader/module-loader' -import type { RouteModule } from '../route-modules/route-module' -import type { AppRouteRouteHandlerContext } from '../route-modules/app-route/module' -import type { AppRouteRouteMatch } from '../route-matches/app-route-route-match' - -import { NodeModuleLoader } from '../helpers/module-loader/node-module-loader' -import { RouteModuleLoader } from '../helpers/module-loader/route-module-loader' -import { NextRequestAdapter } from '../../web/spec-extension/adapters/next-request' - -/** - * RouteHandlerManager is a manager for route handlers. - */ -export type RouteHandlerManagerContext = - // As new route handlers are added, their types should be '&'-ed with this - // type. - AppRouteRouteHandlerContext - -export class RouteHandlerManager { - constructor( - private readonly moduleLoader: ModuleLoader = new NodeModuleLoader() - ) {} - - public async handle( - match: AppRouteRouteMatch, - req: BaseNextRequest, - context: RouteHandlerManagerContext, - signal: AbortSignal - ): Promise { - // The module supports minimal mode, load the minimal module. - const module = await RouteModuleLoader.load( - match.definition.filename, - this.moduleLoader - ) - - // Convert the BaseNextRequest to a NextRequest. - const request = NextRequestAdapter.fromBaseNextRequest(req, signal) - - // Get the response from the handler and send it back. - return await module.handle(request, context) - } -} diff --git a/packages/next/src/server/future/route-matches/route-match.ts b/packages/next/src/server/future/route-matches/route-match.ts index dcc07d3dec9f0..3a4444f17573b 100644 --- a/packages/next/src/server/future/route-matches/route-match.ts +++ b/packages/next/src/server/future/route-matches/route-match.ts @@ -1,4 +1,3 @@ -import type { ParsedUrlQuery } from 'querystring' import type { RouteDefinition } from '../route-definitions/route-definition' /** @@ -15,39 +14,3 @@ export interface RouteMatch { */ readonly params: Record | undefined } - -/** - * Checks if the route match is the specified route match kind. This can also - * be used to coerce the match type. Note that for situations where multiple - * route match types are associated with a given route kind this function will - * not validate it at runtime. - * - * @param match the match to check - * @param kind the kind to check against - * @returns true if the route match is of the specified kind - */ -export function isRouteMatch( - match: RouteMatch, - kind: M['definition']['kind'] -): match is M { - return match.definition.kind === kind -} - -/** - * Converts the query into params. - * - * @param query the query to convert to params - * @returns the params - */ -export function parsedUrlQueryToParams( - query: ParsedUrlQuery -): Record { - const params: Record = {} - - for (const [key, value] of Object.entries(query)) { - if (typeof value === 'undefined') continue - params[key] = value - } - - return params -} diff --git a/packages/next/src/server/future/route-modules/app-page/module.ts b/packages/next/src/server/future/route-modules/app-page/module.ts index 870465551d915..418e37420d7e9 100644 --- a/packages/next/src/server/future/route-modules/app-page/module.ts +++ b/packages/next/src/server/future/route-modules/app-page/module.ts @@ -34,10 +34,6 @@ export class AppPageRouteModule extends RouteModule< AppPageRouteDefinition, AppPageUserlandModule > { - public handle(): Promise { - throw new Error('Method not implemented.') - } - public render( req: IncomingMessage, res: ServerResponse, diff --git a/packages/next/src/server/future/route-modules/app-route/helpers/parsed-url-query-to-params.ts b/packages/next/src/server/future/route-modules/app-route/helpers/parsed-url-query-to-params.ts new file mode 100644 index 0000000000000..6201732b229e2 --- /dev/null +++ b/packages/next/src/server/future/route-modules/app-route/helpers/parsed-url-query-to-params.ts @@ -0,0 +1,20 @@ +import type { ParsedUrlQuery } from 'querystring' + +/** + * Converts the query into params. + * + * @param query the query to convert to params + * @returns the params + */ +export function parsedUrlQueryToParams( + query: ParsedUrlQuery +): Record { + const params: Record = {} + + for (const [key, value] of Object.entries(query)) { + if (typeof value === 'undefined') continue + params[key] = value + } + + return params +} diff --git a/packages/next/src/server/future/route-modules/app-route/module.ts b/packages/next/src/server/future/route-modules/app-route/module.ts index 5ffb9170cf373..1bee78f92179c 100644 --- a/packages/next/src/server/future/route-modules/app-route/module.ts +++ b/packages/next/src/server/future/route-modules/app-route/module.ts @@ -33,6 +33,7 @@ import { autoImplementMethods } from './helpers/auto-implement-methods' import { getNonStaticMethods } from './helpers/get-non-static-methods' import { appendMutableCookies } from '../../../web/spec-extension/adapters/request-cookies' import { RouteKind } from '../../route-kind' +import { parsedUrlQueryToParams } from './helpers/parsed-url-query-to-params' // These are imported weirdly like this because of the way that the bundling // works. We need to import the built files from the dist directory, but we @@ -362,7 +363,9 @@ export class AppRouteRouteModule extends RouteModule< this.staticGenerationAsyncStorage, }) const res = await handler(wrappedRequest, { - params: context.params, + params: context.params + ? parsedUrlQueryToParams(context.params) + : undefined, }) ;(context.staticGenerationContext as any).fetchMetrics = staticGenerationStore.fetchMetrics diff --git a/packages/next/src/server/future/route-modules/pages-api/module.ts b/packages/next/src/server/future/route-modules/pages-api/module.ts index 6147dd4dbdfb6..88dbda73b464c 100644 --- a/packages/next/src/server/future/route-modules/pages-api/module.ts +++ b/packages/next/src/server/future/route-modules/pages-api/module.ts @@ -100,10 +100,6 @@ export class PagesAPIRouteModule extends RouteModule< PagesAPIRouteDefinition, PagesAPIUserlandModule > { - public handle(): Promise { - throw new Error('Method not implemented.') - } - /** * * @param req the incoming server request diff --git a/packages/next/src/server/future/route-modules/pages/module.ts b/packages/next/src/server/future/route-modules/pages/module.ts index e94e10bc9346a..dac8ae5546441 100644 --- a/packages/next/src/server/future/route-modules/pages/module.ts +++ b/packages/next/src/server/future/route-modules/pages/module.ts @@ -110,10 +110,6 @@ export class PagesRouteModule extends RouteModule< this.components = options.components } - public handle(): Promise { - throw new Error('Method not implemented.') - } - public render( req: IncomingMessage, res: ServerResponse, diff --git a/packages/next/src/server/future/route-modules/route-module.ts b/packages/next/src/server/future/route-modules/route-module.ts index e9521edda1fff..52188ed506dff 100644 --- a/packages/next/src/server/future/route-modules/route-module.ts +++ b/packages/next/src/server/future/route-modules/route-module.ts @@ -1,5 +1,4 @@ import type { RouteDefinition } from '../route-definitions/route-definition' -import type { NextRequest } from '../../web/spec-extension/request' /** * RouteModuleOptions is the options that are passed to the route module, other @@ -22,7 +21,7 @@ export interface RouteModuleHandleContext { * Any matched parameters for the request. This is only defined for dynamic * routes. */ - params: Record | undefined + params: Record | undefined } /** @@ -45,14 +44,6 @@ export abstract class RouteModule< */ public readonly definition: Readonly - /** - * Handle will handle the request and return a response. - */ - public abstract handle( - req: NextRequest, - context: RouteModuleHandleContext - ): Promise - constructor({ userland, definition }: RouteModuleOptions) { this.userland = userland this.definition = definition diff --git a/packages/next/src/server/web/edge-route-module-wrapper.ts b/packages/next/src/server/web/edge-route-module-wrapper.ts index 2b19616fb2f1a..5f7e5fa126eea 100644 --- a/packages/next/src/server/web/edge-route-module-wrapper.ts +++ b/packages/next/src/server/web/edge-route-module-wrapper.ts @@ -1,7 +1,8 @@ -import type { RouteHandlerManagerContext } from '../future/route-handler-managers/route-handler-manager' -import type { RouteDefinition } from '../future/route-definitions/route-definition' -import type { RouteModule } from '../future/route-modules/route-module' import type { NextRequest } from './spec-extension/request' +import type { + AppRouteRouteHandlerContext, + AppRouteRouteModule, +} from '../future/route-modules/app-route/module' import './globals' @@ -27,9 +28,7 @@ export class EdgeRouteModuleWrapper { * * @param routeModule the route module to wrap */ - private constructor( - private readonly routeModule: RouteModule - ) { + private constructor(private readonly routeModule: AppRouteRouteModule) { // TODO: (wyattjoh) possibly allow the module to define it's own matcher this.matcher = new RouteMatcher(routeModule.definition) } @@ -44,7 +43,7 @@ export class EdgeRouteModuleWrapper { * @returns a function that can be used as a handler for the edge runtime */ public static wrap( - routeModule: RouteModule, + routeModule: AppRouteRouteModule, options: WrapOptions = {} ) { // Create the module wrapper. @@ -84,7 +83,7 @@ export class EdgeRouteModuleWrapper { // Create the context for the handler. This contains the params from the // match (if any). - const context: RouteHandlerManagerContext = { + const context: AppRouteRouteHandlerContext = { params: match.params, prerenderManifest: { version: 4,