@@ -322,37 +322,35 @@ export const moduleFederationSSRPlugin = (
322322 api . config ( ( ) => {
323323 return {
324324 builderPlugins : [ mfSSRRsbuildPlugin ( pluginOptions ) ] ,
325- tools : {
326- devServer : {
327- before : [
328- ( req , res , next ) => {
329- if ( ! enableSSR ) {
325+ dev : {
326+ setupMiddlewares : ( middlewares ) => {
327+ middlewares . push ( ( req , res , next ) => {
328+ if ( ! enableSSR ) {
329+ next ( ) ;
330+ return ;
331+ }
332+ try {
333+ if (
334+ req . url ?. includes ( '.json' ) &&
335+ ! req . url ?. includes ( 'hot-update' )
336+ ) {
337+ const filepath = path . join ( process . cwd ( ) , `dist${ req . url } ` ) ;
338+ fs . statSync ( filepath ) ;
339+ res . setHeader ( 'Access-Control-Allow-Origin' , '*' ) ;
340+ res . setHeader (
341+ 'Access-Control-Allow-Methods' ,
342+ 'GET, POST, PUT, DELETE, PATCH, OPTIONS' ,
343+ ) ;
344+ res . setHeader ( 'Access-Control-Allow-Headers' , '*' ) ;
345+ fs . createReadStream ( filepath ) . pipe ( res ) ;
346+ } else {
330347 next ( ) ;
331- return ;
332348 }
333- try {
334- if (
335- req . url ?. includes ( '.json' ) &&
336- ! req . url ?. includes ( 'hot-update' )
337- ) {
338- const filepath = path . join ( process . cwd ( ) , `dist${ req . url } ` ) ;
339- fs . statSync ( filepath ) ;
340- res . setHeader ( 'Access-Control-Allow-Origin' , '*' ) ;
341- res . setHeader (
342- 'Access-Control-Allow-Methods' ,
343- 'GET, POST, PUT, DELETE, PATCH, OPTIONS' ,
344- ) ;
345- res . setHeader ( 'Access-Control-Allow-Headers' , '*' ) ;
346- fs . createReadStream ( filepath ) . pipe ( res ) ;
347- } else {
348- next ( ) ;
349- }
350- } catch ( err ) {
351- logger . debug ( err ) ;
352- next ( ) ;
353- }
354- } ,
355- ] ,
349+ } catch ( err ) {
350+ logger . debug ( err ) ;
351+ next ( ) ;
352+ }
353+ } ) ;
356354 } ,
357355 } ,
358356 } ;
0 commit comments