@@ -70,11 +70,11 @@ export function addDefaultMiddlewareFuncs(app) {
7070 } ,
7171 resave : getConfig ( 'system.session.resave' , false ) ,
7272 saveUninitialized : getConfig ( 'system.session.saveUninitialized' , true )
73- } ;
73+ } as session . SessionOptions ;
7474
7575 if ( isProductionMode ( ) ) {
7676 app . set ( 'trust proxy' , 1 ) ;
77- sess . cookie . secure = false ;
77+ sess . cookie ! . secure = false ;
7878 }
7979
8080 const adminSessionMiddleware = session ( {
@@ -156,7 +156,7 @@ export function addDefaultMiddlewareFuncs(app) {
156156 if ( match ) {
157157 request . locals = request . locals || { } ;
158158 request . locals . customParams = { } ;
159- const keys = [ ] ;
159+ const keys : any [ ] = [ ] ;
160160 pathToRegexp ( r . path , keys ) ;
161161 keys . forEach ( ( key , index ) => {
162162 request . locals . customParams [ key . name ] = match [ index + 1 ] ;
@@ -182,10 +182,7 @@ export function addDefaultMiddlewareFuncs(app) {
182182 return next ( ) ;
183183 }
184184
185- const routes = getRoutes ( ) ;
186185 const route = findRoute ( request ) ;
187- request . locals = request . locals || { } ;
188- request . locals . webpackMatchedRoute = route ;
189186 if ( ! route || ! isBuildRequired ( route ) ) {
190187 next ( ) ;
191188 } else {
@@ -222,100 +219,55 @@ export function addDefaultMiddlewareFuncs(app) {
222219 path . join ( theme . path , 'dist' , '**' , '[A-Z]*.js' )
223220 ) ;
224221 }
225- if ( ! route . webpackCompiler ) {
226- route . webpackCompiler = webpack (
222+ if ( ! app . locals . webpackCompiler ) {
223+ app . locals . webpackCompiler = webpack (
227224 createConfigClient (
228- route ,
229- route . isAdmin ? adminTailwindConfig : frontStoreTailwindConfig
230- )
225+ adminTailwindConfig ,
226+ frontStoreTailwindConfig
227+ ) as any
231228 ) ;
232229 }
233- const { webpackCompiler } = route ;
230+ const { webpackCompiler } = app . locals ;
234231 let middlewareFunc ;
235- if ( ! route . webpackMiddleware ) {
236- middlewareFunc = route . webpackMiddleware = middleware ( webpackCompiler , {
237- serverSideRender : true ,
238- publicPath : '/' ,
239- stats : 'none'
240- } ) ;
241- middlewareFunc . context . logger . info = ( ) => { } ;
242- } else {
243- middlewareFunc = route . webpackMiddleware ;
244- }
245- middlewareFunc . waitUntilValid ( ( ) => {
246- const { stats } = middlewareFunc . context ;
247- const jsonWebpackStats = stats . toJson ( ) ;
248- response . locals . jsonWebpackStats = jsonWebpackStats ;
249- } ) ;
250- // We need to run build for notFound route
251- const notFoundRoute = routes . find ( ( r ) => r . id === 'notFound' ) ;
252- if ( ! notFoundRoute . webpackCompiler ) {
253- notFoundRoute . webpackCompiler = webpack (
254- createConfigClient ( notFoundRoute , frontStoreTailwindConfig )
255- ) ;
256- }
257- const notFoundWebpackCompiler = notFoundRoute . webpackCompiler ;
258- let notFoundMiddlewareFunc ;
259- if ( ! notFoundRoute . webpackMiddleware ) {
260- notFoundMiddlewareFunc = notFoundRoute . webpackMiddleware = middleware (
261- notFoundWebpackCompiler ,
232+ if ( ! app . locals . webpackMiddleware ) {
233+ middlewareFunc = app . locals . webpackMiddleware = middleware (
234+ webpackCompiler ,
262235 {
263236 serverSideRender : true ,
264237 publicPath : '/' ,
265238 stats : 'none'
266239 }
267240 ) ;
268- notFoundMiddlewareFunc . context . logger . info = ( ) => { } ;
269- } else {
270- notFoundMiddlewareFunc = notFoundRoute . webpackMiddleware ;
271- }
272-
273- // We need to run build for adminNotFound route
274- const adminNotFoundRoute = routes . find ( ( r ) => r . id === 'adminNotFound' ) ;
275- if ( ! adminNotFoundRoute . webpackCompiler ) {
276- adminNotFoundRoute . webpackCompiler = webpack (
277- createConfigClient ( adminNotFoundRoute , adminTailwindConfig )
278- ) ;
279- }
280- const adminNotFoundWebpackCompiler = adminNotFoundRoute . webpackCompiler ;
281- let adminNotFoundMiddlewareFunc ;
282- if ( ! adminNotFoundRoute . webpackMiddleware ) {
283- adminNotFoundMiddlewareFunc = adminNotFoundRoute . webpackMiddleware =
284- middleware ( adminNotFoundWebpackCompiler , {
285- serverSideRender : true ,
286- publicPath : '/' ,
287- stats : 'none'
288- } ) ;
289- adminNotFoundMiddlewareFunc . context . logger . info = ( ) => { } ;
241+ middlewareFunc . context . logger . info = ( ) => { } ;
290242 } else {
291- adminNotFoundMiddlewareFunc = adminNotFoundRoute . webpackMiddleware ;
243+ middlewareFunc = app . locals . webpackMiddleware ;
292244 }
293-
294- middlewareFunc ( request , response , ( ) => {
295- notFoundMiddlewareFunc ( request , response , ( ) => {
296- adminNotFoundMiddlewareFunc ( request , response , next ) ;
297- } ) ;
245+ middlewareFunc . waitUntilValid ( ( ) => {
246+ const { stats } = middlewareFunc . context ;
247+ const jsonWebpackStats = stats . toJson ( ) ;
248+ response . locals . jsonWebpackStats = jsonWebpackStats ;
298249 } ) ;
250+
251+ middlewareFunc ( request , response , next ) ;
299252 }
300253 } ) ;
301254 app . use ( ( request , response , next ) => {
302255 if ( ! isDevelopmentMode ( ) ) {
303256 return next ( ) ;
304257 }
305- const routes = getRoutes ( ) ;
306258 const route = findRoute ( request ) ;
307259 request . currentRoute = route ;
308260 if ( ! isBuildRequired ( route ) ) {
309261 return next ( ) ;
310262 }
311- if ( ! route . hotMiddleware ) {
312- const { webpackCompiler } = route ;
263+ if ( ! app . locals . hotMiddleware ) {
264+ const { webpackCompiler } = app . locals ;
313265 const hotMiddleware = webpackHotMiddleware ( webpackCompiler , {
314- path : `/eHot/ ${ route . id } `
266+ path : `/eHot`
315267 } ) ;
316- route . hotMiddleware = hotMiddleware ;
268+ app . locals . hotMiddleware = hotMiddleware ;
317269 }
318- return route . hotMiddleware ( request , response , ( ) => {
270+ return app . locals . hotMiddleware ( request , response , ( ) => {
319271 next ( ) ;
320272 } ) ;
321273 } ) ;
0 commit comments