@@ -14,6 +14,7 @@ import { lowercaseKeyObject } from '~/dobs/shared/object';
1414import { dynamicImport } from './load' ;
1515import nodeExternal from './plugins/external' ;
1616import { mkdirSync , writeFileSync } from 'node:fs' ;
17+ import { createPluginRunner } from '../plugin' ;
1718
1819type HandlerType = ( ( req : AppRequest , res : AppResponse ) => any ) | Record < string , any > ;
1920
@@ -90,6 +91,7 @@ export function createInternalRouter(
9091 cachedModule : Map < string , any > ,
9192 preloadedModules ?: Map < string , any > ,
9293) {
94+ const pluginRunner = createPluginRunner ( config . plugins ) ;
9395 const routesDirectory = join ( config . cwd , 'app' ) ;
9496
9597 const matchRoute = ( url : string ) => routes . find ( ( route ) => route . regex . test ( url ) ) ;
@@ -113,7 +115,7 @@ export function createInternalRouter(
113115
114116 try {
115117 const method = ( req . method || '' ) . toLowerCase ( ) ;
116- const handlers : PageType = pageModule ;
118+ const handlers : PageType = await pluginRunner . execute ( 'generateRoute' , pageModule ) ;
117119
118120 const execute = async ( handler : HandlerType ) => {
119121 if ( typeof handler !== 'function' ) return res . send ( handler ) ;
@@ -140,25 +142,35 @@ export function createInternalRouter(
140142export async function createRouterMiddleware (
141143 config : ResolvedServerConfig ,
142144) : Promise < Middleware > {
145+ const pluginRunner = createPluginRunner ( config . plugins ) ;
146+
143147 const routesDirectory = join ( config . cwd , 'app' ) ;
144148 const tempDirectory = join ( config . cwd , config . temp , 'routes' ) ;
145149 const tempDirectoryPackageJSON = join ( config . cwd , config . temp , 'package.json' ) ;
150+
146151 const cachedModule = new Map < string , any > ( ) ;
147- const buildOption : ( ) => BuildOptions = ( ) => ( {
148- input : routes . map ( ( route ) => join ( routesDirectory , route . relativePath ) ) ,
149- output : {
150- format : 'cjs' ,
151- sourcemap : true ,
152- esModule : true ,
153- dir : tempDirectory ,
154- } ,
155- resolve : {
156- conditionNames : [ 'require' , 'node' , 'default' ] ,
157- } ,
158- write : false ,
159- // exclude /node_modules/
160- plugins : [ nodeExternal ( ) ] ,
161- } ) ;
152+ const buildOption : ( ) => BuildOptions = ( ) => {
153+ const bo : BuildOptions = {
154+ input : routes . map ( ( route ) => join ( routesDirectory , route . relativePath ) ) ,
155+ output : {
156+ format : 'cjs' ,
157+ sourcemap : true ,
158+ esModule : true ,
159+ dir : tempDirectory ,
160+ } ,
161+ resolve : {
162+ conditionNames : [ 'require' , 'node' , 'default' ] ,
163+ } ,
164+ write : false ,
165+ // exclude /node_modules/
166+ plugins : [ nodeExternal ( ) ] ,
167+ } ;
168+
169+ // [plugin] execute plugin.resolveBuildOptions
170+ pluginRunner . execute ( 'resolveBuildOptions' , bo ) ;
171+
172+ return bo ;
173+ } ;
162174 let routes = createRoutes ( config ) ;
163175
164176 // build initially (prod/dev)
0 commit comments