@@ -5,7 +5,6 @@ import type {
5
5
import type { EdgeSSRMeta } from '../loaders/get-module-build-info'
6
6
import type { MiddlewareMatcher } from '../../analysis/get-page-static-info'
7
7
import { getNamedMiddlewareRegex } from '../../../shared/lib/router/utils/route-regex'
8
- import { getDefaultMiddlewareMatcher } from '../../../shared/lib/router/utils/get-default-middleware-matcher'
9
8
import { getModuleBuildInfo } from '../loaders/get-module-build-info'
10
9
import { getSortedRoutes } from '../../../shared/lib/router/utils'
11
10
import { webpack , sources } from 'next/dist/compiled/webpack/webpack'
@@ -37,7 +36,6 @@ import type { CustomRoutes } from '../../../lib/load-custom-routes'
37
36
import { isInterceptionRouteRewrite } from '../../../lib/generate-interception-routes-rewrites'
38
37
import { getDynamicCodeEvaluationError } from './wellknown-errors-plugin/parse-dynamic-code-evaluation-error'
39
38
import { getModuleReferencesInOrder } from '../utils'
40
- import type { NextConfigComplete } from '../../../server/config-shared'
41
39
42
40
const KNOWN_SAFE_DYNAMIC_PACKAGES =
43
41
require ( '../../../lib/known-edge-safe-packages.json' ) as string [ ]
@@ -197,29 +195,21 @@ function getCreateAssets(params: {
197
195
continue
198
196
}
199
197
200
- let matchers : MiddlewareMatcher [ ]
201
- if ( metadata ?. edgeMiddleware ?. matchers ) {
202
- matchers = metadata . edgeMiddleware . matchers
203
- } else {
204
- // For middleware at root with no explicit matchers, use getDefaultMiddlewareMatcher
205
- // which respects skipMiddlewareNextInternalRoutes config
206
- const catchAll = ! metadata . edgeSSR && ! metadata . edgeApiFunction
207
- if ( page === '/' && catchAll ) {
208
- matchers = [ getDefaultMiddlewareMatcher ( opts . nextConfig ) ]
209
- } else {
210
- const matcherSource = metadata . edgeSSR ?. isAppDir
211
- ? normalizeAppPath ( page )
212
- : page
213
- matchers = [
214
- {
215
- regexp : getNamedMiddlewareRegex ( matcherSource , {
216
- catchAll,
217
- } ) . namedRegex ,
218
- originalSource : matcherSource ,
219
- } ,
220
- ]
221
- }
222
- }
198
+ const matcherSource = metadata . edgeSSR ?. isAppDir
199
+ ? normalizeAppPath ( page )
200
+ : page
201
+
202
+ const catchAll = ! metadata . edgeSSR && ! metadata . edgeApiFunction
203
+
204
+ const { namedRegex } = getNamedMiddlewareRegex ( matcherSource , {
205
+ catchAll,
206
+ } )
207
+ const matchers = metadata ?. edgeMiddleware ?. matchers ?? [
208
+ {
209
+ regexp : namedRegex ,
210
+ originalSource : page === '/' && catchAll ? '/:path*' : matcherSource ,
211
+ } ,
212
+ ]
223
213
224
214
const isEdgeFunction = ! ! ( metadata . edgeApiFunction || metadata . edgeSSR )
225
215
const edgeFunctionDefinition : EdgeFunctionDefinition = {
@@ -828,28 +818,19 @@ interface Options {
828
818
sriEnabled : boolean
829
819
rewrites : CustomRoutes [ 'rewrites' ]
830
820
edgeEnvironments : EdgeRuntimeEnvironments
831
- nextConfig : NextConfigComplete
832
821
}
833
822
834
823
export default class MiddlewarePlugin {
835
824
private readonly dev : Options [ 'dev' ]
836
825
private readonly sriEnabled : Options [ 'sriEnabled' ]
837
826
private readonly rewrites : Options [ 'rewrites' ]
838
827
private readonly edgeEnvironments : EdgeRuntimeEnvironments
839
- private readonly nextConfig : Options [ 'nextConfig' ]
840
-
841
- constructor ( {
842
- dev,
843
- sriEnabled,
844
- rewrites,
845
- edgeEnvironments,
846
- nextConfig,
847
- } : Options ) {
828
+
829
+ constructor ( { dev, sriEnabled, rewrites, edgeEnvironments } : Options ) {
848
830
this . dev = dev
849
831
this . sriEnabled = sriEnabled
850
832
this . rewrites = rewrites
851
833
this . edgeEnvironments = edgeEnvironments
852
- this . nextConfig = nextConfig
853
834
}
854
835
855
836
public apply ( compiler : webpack . Compiler ) {
@@ -905,7 +886,6 @@ export default class MiddlewarePlugin {
905
886
rewrites : this . rewrites ,
906
887
edgeEnvironments : this . edgeEnvironments ,
907
888
dev : this . dev ,
908
- nextConfig : this . nextConfig ,
909
889
} ,
910
890
} )
911
891
)
0 commit comments