Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
e7208a12
Unverified
Commit
e7208a12
authored
Oct 27, 2022
by
JJ Kasper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[edge] serialize custom config to middleware-manifest
Co-authored-by:
Gal Schlezinger
<
gal@spitfire.co.il
>
parent
980095d5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
2 deletions
+32
-2
get-page-static-info.ts
packages/next/build/analysis/get-page-static-info.ts
+10
-1
middleware-plugin.ts
packages/next/build/webpack/plugins/middleware-plugin.ts
+7
-0
middleware.js
test/e2e/middleware-general/app/middleware.js
+2
-0
edge-search-params.js
...2e/middleware-general/app/pages/api/edge-search-params.js
+1
-1
index.test.ts
test/e2e/middleware-general/test/index.test.ts
+12
-0
No files found.
packages/next/build/analysis/get-page-static-info.ts
View file @
e7208a12
...
...
@@ -18,6 +18,7 @@ import { RSC_MODULE_TYPES } from '../../shared/lib/constants'
export
interface
MiddlewareConfig
{
matchers
:
MiddlewareMatcher
[]
unstable_allowDynamicGlobs
:
string
[]
regions
:
string
[]
|
string
}
export
interface
MiddlewareMatcher
{
...
...
@@ -184,6 +185,14 @@ function getMiddlewareConfig(
result
.
matchers
=
getMiddlewareMatchers
(
config
.
matcher
,
nextConfig
)
}
if
(
typeof
config
.
regions
===
'string'
||
Array
.
isArray
(
config
.
regions
))
{
result
.
regions
=
config
.
regions
}
else
if
(
typeof
config
.
regions
!==
'undefined'
)
{
Log
.
warn
(
`The \`regions\` config was ignored: config must be empty, a string or an array of strings. (
${
pageFilePath
}
)`
)
}
if
(
config
.
unstable_allowDynamic
)
{
result
.
unstable_allowDynamicGlobs
=
Array
.
isArray
(
config
.
unstable_allowDynamic
...
...
@@ -256,7 +265,7 @@ export async function getPageStaticInfo(params: {
const
fileContent
=
(
await
tryToReadFile
(
pageFilePath
,
!
isDev
))
||
''
if
(
/runtime|getStaticProps|getServerSideProps|matcher|unstable_allowDynamic/
.
test
(
/runtime|getStaticProps|getServerSideProps|matcher|unstable_allowDynamic
|export const config
/
.
test
(
fileContent
)
)
{
...
...
packages/next/build/webpack/plugins/middleware-plugin.ts
View file @
e7208a12
...
...
@@ -35,6 +35,7 @@ export interface EdgeFunctionDefinition {
matchers
:
MiddlewareMatcher
[]
wasm
?:
AssetBinding
[]
assets
?:
AssetBinding
[]
regions
?:
string
[]
|
string
}
export
interface
MiddlewareManifest
{
...
...
@@ -51,6 +52,7 @@ interface EntryMetadata {
env
:
Set
<
string
>
wasmBindings
:
Map
<
string
,
string
>
assetBindings
:
Map
<
string
,
string
>
regions
?:
string
[]
|
string
}
const
NAME
=
'MiddlewarePlugin'
...
...
@@ -173,6 +175,7 @@ function getCreateAssets(params: {
name
,
filePath
,
})),
...(
metadata
.
regions
&&
{
regions
:
metadata
.
regions
}),
}
if
(
metadata
.
edgeApiFunction
||
metadata
.
edgeSSR
)
{
...
...
@@ -732,6 +735,10 @@ function getExtractMetadata(params: {
}
}
if
(
edgeFunctionConfig
?.
config
?.
regions
)
{
entryMetadata
.
regions
=
edgeFunctionConfig
.
config
.
regions
}
/**
* The entry module has to be either a page or a middleware and hold
* the corresponding metadata.
...
...
test/e2e/middleware-general/app/middleware.js
View file @
e7208a12
...
...
@@ -2,6 +2,8 @@
import
{
NextRequest
,
NextResponse
,
URLPattern
}
from
'next/server'
import
magicValue
from
'shared-package'
export
const
config
=
{
regions
:
'auto'
}
const
PATTERNS
=
[
[
new
URLPattern
({
pathname
:
'/:locale/:id'
}),
...
...
test/e2e/middleware-general/app/pages/api/edge-search-params.js
View file @
e7208a12
import
{
NextResponse
}
from
'next/server'
export
const
config
=
{
runtime
:
'experimental-edge'
}
export
const
config
=
{
runtime
:
'experimental-edge'
,
regions
:
'default'
}
/**
* @param {import('next/server').NextRequest}
...
...
test/e2e/middleware-general/test/index.test.ts
View file @
e7208a12
...
...
@@ -125,10 +125,22 @@ describe('Middleware Runtime', () => {
matchers
:
[{
regexp
:
'^/.*$'
}],
wasm
:
[],
assets
:
[],
regions
:
'auto'
,
},
})
})
it
(
'should have the custom config in the manifest'
,
async
()
=>
{
const
manifest
=
await
fs
.
readJSON
(
join
(
next
.
testDir
,
'.next/server/middleware-manifest.json'
)
)
expect
(
manifest
.
functions
[
'/api/edge-search-params'
]).
toHaveProperty
(
'regions'
,
'default'
)
})
it
(
'should have correct files in manifest'
,
async
()
=>
{
const
manifest
=
await
fs
.
readJSON
(
join
(
next
.
testDir
,
'.next/server/middleware-manifest.json'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment