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
0381cf09
Unverified
Commit
0381cf09
authored
Nov 09, 2022
by
JJ Kasper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add missing matcher support
parent
b9c74083
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
256 additions
and
140 deletions
+256
-140
get-page-static-info.ts
packages/next/build/analysis/get-page-static-info.ts
+1
-0
utils.ts
...ext/build/webpack/loaders/next-serverless-loader/utils.ts
+7
-2
load-custom-routes.ts
packages/next/lib/load-custom-routes.ts
+71
-36
router.ts
packages/next/server/router.ts
+8
-2
middleware-route-matcher.ts
.../next/shared/lib/router/utils/middleware-route-matcher.ts
+2
-2
prepare-destination.ts
packages/next/shared/lib/router/utils/prepare-destination.ts
+9
-4
resolve-rewrites.ts
packages/next/shared/lib/router/utils/resolve-rewrites.ts
+3
-2
middleware.js
test/e2e/middleware-custom-matchers/app/middleware.js
+20
-0
index.test.ts
test/e2e/middleware-custom-matchers/test/index.test.ts
+22
-0
next.config.js
test/integration/custom-routes/next.config.js
+32
-1
index.test.js
test/integration/custom-routes/test/index.test.js
+81
-91
No files found.
packages/next/build/analysis/get-page-static-info.ts
View file @
0381cf09
...
@@ -25,6 +25,7 @@ export interface MiddlewareMatcher {
...
@@ -25,6 +25,7 @@ export interface MiddlewareMatcher {
regexp
:
string
regexp
:
string
locale
?:
false
locale
?:
false
has
?:
RouteHas
[]
has
?:
RouteHas
[]
missing
?:
RouteHas
[]
}
}
export
interface
PageStaticInfo
{
export
interface
PageStaticInfo
{
...
...
packages/next/build/webpack/loaders/next-serverless-loader/utils.ts
View file @
0381cf09
...
@@ -157,8 +157,13 @@ export function getUtils({
...
@@ -157,8 +157,13 @@ export function getUtils({
)
)
let
params
=
matcher
(
parsedUrl
.
pathname
)
let
params
=
matcher
(
parsedUrl
.
pathname
)
if
(
rewrite
.
has
&&
params
)
{
if
((
rewrite
.
has
||
rewrite
.
missing
)
&&
params
)
{
const
hasParams
=
matchHas
(
req
,
rewrite
.
has
,
parsedUrl
.
query
)
const
hasParams
=
matchHas
(
req
,
parsedUrl
.
query
,
rewrite
.
has
,
rewrite
.
missing
)
if
(
hasParams
)
{
if
(
hasParams
)
{
Object
.
assign
(
params
,
hasParams
)
Object
.
assign
(
params
,
hasParams
)
...
...
packages/next/lib/load-custom-routes.ts
View file @
0381cf09
...
@@ -24,6 +24,7 @@ export type Rewrite = {
...
@@ -24,6 +24,7 @@ export type Rewrite = {
basePath
?:
false
basePath
?:
false
locale
?:
false
locale
?:
false
has
?:
RouteHas
[]
has
?:
RouteHas
[]
missing
?:
RouteHas
[]
}
}
export
type
Header
=
{
export
type
Header
=
{
...
@@ -32,6 +33,7 @@ export type Header = {
...
@@ -32,6 +33,7 @@ export type Header = {
locale
?:
false
locale
?:
false
headers
:
Array
<
{
key
:
string
;
value
:
string
}
>
headers
:
Array
<
{
key
:
string
;
value
:
string
}
>
has
?:
RouteHas
[]
has
?:
RouteHas
[]
missing
?:
RouteHas
[]
}
}
// internal type used for validation (not user facing)
// internal type used for validation (not user facing)
...
@@ -41,6 +43,7 @@ export type Redirect = {
...
@@ -41,6 +43,7 @@ export type Redirect = {
basePath
?:
false
basePath
?:
false
locale
?:
false
locale
?:
false
has
?:
RouteHas
[]
has
?:
RouteHas
[]
missing
?:
RouteHas
[]
}
&
(
}
&
(
|
{
|
{
statusCode
?:
never
statusCode
?:
never
...
@@ -56,6 +59,7 @@ export type Middleware = {
...
@@ -56,6 +59,7 @@ export type Middleware = {
source
:
string
source
:
string
locale
?:
false
locale
?:
false
has
?:
RouteHas
[]
has
?:
RouteHas
[]
missing
?:
RouteHas
[]
}
}
const
allowedHasTypes
=
new
Set
([
'header'
,
'cookie'
,
'query'
,
'host'
])
const
allowedHasTypes
=
new
Set
([
'header'
,
'cookie'
,
'query'
,
'host'
])
...
@@ -132,8 +136,9 @@ export function checkCustomRoutes(
...
@@ -132,8 +136,9 @@ export function checkCustomRoutes(
let
numInvalidRoutes
=
0
let
numInvalidRoutes
=
0
let
hadInvalidStatus
=
false
let
hadInvalidStatus
=
false
let
hadInvalidHas
=
false
let
hadInvalidHas
=
false
let
hadInvalidMissing
=
false
const
allowedKeys
=
new
Set
<
string
>
([
'source'
,
'locale'
,
'has'
])
const
allowedKeys
=
new
Set
<
string
>
([
'source'
,
'locale'
,
'has'
,
'missing'
])
if
(
type
===
'rewrite'
)
{
if
(
type
===
'rewrite'
)
{
allowedKeys
.
add
(
'basePath'
)
allowedKeys
.
add
(
'basePath'
)
...
@@ -198,13 +203,21 @@ export function checkCustomRoutes(
...
@@ -198,13 +203,21 @@ export function checkCustomRoutes(
invalidParts
.
push
(
'`locale` must be undefined or false'
)
invalidParts
.
push
(
'`locale` must be undefined or false'
)
}
}
if
(
typeof
route
.
has
!==
'undefined'
&&
!
Array
.
isArray
(
route
.
has
))
{
const
checkInvalidHasMissing
=
(
invalidParts
.
push
(
'`has` must be undefined or valid has object'
)
items
:
any
,
hadInvalidHas
=
true
fieldName
:
'has'
|
'missing'
}
else
if
(
route
.
has
)
{
)
=>
{
let
hadInvalidItem
=
false
if
(
typeof
items
!==
'undefined'
&&
!
Array
.
isArray
(
items
))
{
invalidParts
.
push
(
`\`
${
fieldName
}
\` must be undefined or valid has object`
)
hadInvalidItem
=
true
}
else
if
(
items
)
{
const
invalidHasItems
=
[]
const
invalidHasItems
=
[]
for
(
const
hasItem
of
route
.
ha
s
)
{
for
(
const
hasItem
of
item
s
)
{
let
invalidHasParts
=
[]
let
invalidHasParts
=
[]
if
(
!
allowedHasTypes
.
has
(
hasItem
.
type
))
{
if
(
!
allowedHasTypes
.
has
(
hasItem
.
type
))
{
...
@@ -231,16 +244,25 @@ export function checkCustomRoutes(
...
@@ -231,16 +244,25 @@ export function checkCustomRoutes(
}
}
if
(
invalidHasItems
.
length
>
0
)
{
if
(
invalidHasItems
.
length
>
0
)
{
hadInvalidHas
=
true
hadInvalidItem
=
true
const
itemStr
=
`item
${
invalidHasItems
.
length
===
1
?
''
:
's'
}
`
const
itemStr
=
`item
${
invalidHasItems
.
length
===
1
?
''
:
's'
}
`
console
.
error
(
console
.
error
(
`Invalid \`has\`
${
itemStr
}
:\n`
+
invalidHasItems
.
join
(
'
\
n'
)
`Invalid \`
${
fieldName
}
\`
${
itemStr
}
:\n`
+
invalidHasItems
.
join
(
'
\
n'
)
)
)
console
.
error
()
console
.
error
()
invalidParts
.
push
(
`invalid \`has
\`
${
itemStr
}
found`
)
invalidParts
.
push
(
`invalid \`
${
fieldName
}
\`
${
itemStr
}
found`
)
}
}
}
}
return
hadInvalidItem
}
if
(
checkInvalidHasMissing
(
route
.
has
,
'has'
))
{
hadInvalidHas
=
true
}
if
(
checkInvalidHasMissing
(
route
.
missing
,
'missing'
))
{
hadInvalidMissing
=
true
}
if
(
!
route
.
source
)
{
if
(
!
route
.
source
)
{
invalidParts
.
push
(
'`source` is missing'
)
invalidParts
.
push
(
'`source` is missing'
)
...
@@ -421,6 +443,19 @@ export function checkCustomRoutes(
...
@@ -421,6 +443,19 @@ export function checkCustomRoutes(
)}
`
)}
`
)
)
}
}
if
(
hadInvalidMissing
)
{
console
.
error
(
`\nValid \`missing\` object shape is
${
JSON
.
stringify
(
{
type
:
[...
allowedHasTypes
].
join
(
', '
),
key
:
'the key to check for'
,
value
:
'undefined or a value string to match against'
,
},
null
,
2
)}
`
)
}
console
.
error
()
console
.
error
()
console
.
error
(
console
.
error
(
`Error: Invalid
${
type
}${
numInvalidRoutes
===
1
?
''
:
's'
}
found`
`Error: Invalid
${
type
}${
numInvalidRoutes
===
1
?
''
:
's'
}
found`
...
...
packages/next/server/router.ts
View file @
0381cf09
...
@@ -30,6 +30,7 @@ type RouteResult = {
...
@@ -30,6 +30,7 @@ type RouteResult = {
export
type
Route
=
{
export
type
Route
=
{
match
:
RouteMatch
match
:
RouteMatch
has
?:
RouteHas
[]
has
?:
RouteHas
[]
missing
?:
RouteHas
[]
type
:
string
type
:
string
check
?:
boolean
check
?:
boolean
statusCode
?:
number
statusCode
?:
number
...
@@ -416,8 +417,13 @@ export default class Router {
...
@@ -416,8 +417,13 @@ export default class Router {
})
})
let
params
=
route
.
match
(
matchPathname
)
let
params
=
route
.
match
(
matchPathname
)
if
(
route
.
has
&&
params
)
{
if
((
route
.
has
||
route
.
missing
)
&&
params
)
{
const
hasParams
=
matchHas
(
req
,
route
.
has
,
parsedUrlUpdated
.
query
)
const
hasParams
=
matchHas
(
req
,
parsedUrlUpdated
.
query
,
route
.
has
,
route
.
missing
)
if
(
hasParams
)
{
if
(
hasParams
)
{
Object
.
assign
(
params
,
hasParams
)
Object
.
assign
(
params
,
hasParams
)
}
else
{
}
else
{
...
...
packages/next/shared/lib/router/utils/middleware-route-matcher.ts
View file @
0381cf09
...
@@ -25,8 +25,8 @@ export function getMiddlewareRouteMatcher(
...
@@ -25,8 +25,8 @@ export function getMiddlewareRouteMatcher(
continue
continue
}
}
if
(
matcher
.
has
)
{
if
(
matcher
.
has
||
matcher
.
missing
)
{
const
hasParams
=
matchHas
(
req
,
matcher
.
has
,
query
)
const
hasParams
=
matchHas
(
req
,
query
,
matcher
.
has
,
matcher
.
missing
)
if
(
!
hasParams
)
{
if
(
!
hasParams
)
{
continue
continue
}
}
...
...
packages/next/shared/lib/router/utils/prepare-destination.ts
View file @
0381cf09
...
@@ -42,12 +42,13 @@ function unescapeSegments(str: string) {
...
@@ -42,12 +42,13 @@ function unescapeSegments(str: string) {
export
function
matchHas
(
export
function
matchHas
(
req
:
BaseNextRequest
|
IncomingMessage
,
req
:
BaseNextRequest
|
IncomingMessage
,
has
:
RouteHas
[],
query
:
Params
,
query
:
Params
has
:
RouteHas
[]
=
[],
missing
:
RouteHas
[]
=
[]
):
false
|
Params
{
):
false
|
Params
{
const
params
:
Params
=
{}
const
params
:
Params
=
{}
const
allMatch
=
has
.
every
((
hasItem
)
=>
{
const
hasMatch
=
(
hasItem
:
RouteHas
)
=>
{
let
value
:
undefined
|
string
let
value
:
undefined
|
string
let
key
=
hasItem
.
key
let
key
=
hasItem
.
key
...
@@ -100,7 +101,11 @@ export function matchHas(
...
@@ -100,7 +101,11 @@ export function matchHas(
}
}
}
}
return
false
return
false
})
}
const
allMatch
=
has
.
every
((
item
)
=>
hasMatch
(
item
))
&&
!
missing
.
some
((
item
)
=>
hasMatch
(
item
))
if
(
allMatch
)
{
if
(
allMatch
)
{
return
params
return
params
...
...
packages/next/shared/lib/router/utils/resolve-rewrites.ts
View file @
0381cf09
...
@@ -44,7 +44,7 @@ export default function resolveRewrites(
...
@@ -44,7 +44,7 @@ export default function resolveRewrites(
let
params
=
matcher
(
parsedAs
.
pathname
)
let
params
=
matcher
(
parsedAs
.
pathname
)
if
(
rewrite
.
has
&&
params
)
{
if
(
(
rewrite
.
has
||
rewrite
.
missing
)
&&
params
)
{
const
hasParams
=
matchHas
(
const
hasParams
=
matchHas
(
{
{
headers
:
{
headers
:
{
...
@@ -58,8 +58,9 @@ export default function resolveRewrites(
...
@@ -58,8 +58,9 @@ export default function resolveRewrites(
return
acc
return
acc
},
{}),
},
{}),
}
as
any
,
}
as
any
,
parsedAs
.
query
,
rewrite
.
has
,
rewrite
.
has
,
parsedAs
.
query
rewrite
.
missing
)
)
if
(
hasParams
)
{
if
(
hasParams
)
{
...
...
test/e2e/middleware-custom-matchers/app/middleware.js
View file @
0381cf09
...
@@ -57,5 +57,25 @@ export const config = {
...
@@ -57,5 +57,25 @@ export const config = {
},
},
],
],
},
},
{
source
:
'/missing-match-1'
,
missing
:
[
{
type
:
'header'
,
key
:
'hello'
,
value
:
'(.*)'
,
},
],
},
{
source
:
'/missing-match-2'
,
missing
:
[
{
type
:
'query'
,
key
:
'test'
,
value
:
'value'
,
},
],
},
],
],
}
}
test/e2e/middleware-custom-matchers/test/index.test.ts
View file @
0381cf09
...
@@ -21,6 +21,28 @@ describe('Middleware custom matchers', () => {
...
@@ -21,6 +21,28 @@ describe('Middleware custom matchers', () => {
afterAll
(()
=>
next
.
destroy
())
afterAll
(()
=>
next
.
destroy
())
const
runTests
=
()
=>
{
const
runTests
=
()
=>
{
it
(
'should match missing header correctly'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
next
.
url
,
'/missing-match-1'
)
expect
(
res
.
headers
.
get
(
'x-from-middleware'
)).
toBeDefined
()
const
res2
=
await
fetchViaHTTP
(
next
.
url
,
'/missing-match-1'
,
undefined
,
{
headers
:
{
hello
:
'world'
,
},
})
expect
(
res2
.
headers
.
get
(
'x-from-middleware'
)).
toBeFalsy
()
})
it
(
'should match missing query correctly'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
next
.
url
,
'/missing-match-2'
)
expect
(
res
.
headers
.
get
(
'x-from-middleware'
)).
toBeDefined
()
const
res2
=
await
fetchViaHTTP
(
next
.
url
,
'/missing-match-2'
,
{
test
:
'value'
,
})
expect
(
res2
.
headers
.
get
(
'x-from-middleware'
)).
toBeFalsy
()
})
it
(
'should match source path'
,
async
()
=>
{
it
(
'should match source path'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
next
.
url
,
'/source-match'
)
const
res
=
await
fetchViaHTTP
(
next
.
url
,
'/source-match'
)
expect
(
res
.
status
).
toBe
(
200
)
expect
(
res
.
status
).
toBe
(
200
)
...
...
test/integration/custom-routes/next.config.js
View file @
0381cf09
module
.
exports
=
{
module
.
exports
=
{
// target: 'serverless',
async
rewrites
()
{
async
rewrites
()
{
// no-rewrites comment
// no-rewrites comment
return
{
return
{
...
@@ -205,6 +204,38 @@ module.exports = {
...
@@ -205,6 +204,38 @@ module.exports = {
],
],
destination
:
'/blog-catchall/:post'
,
destination
:
'/blog-catchall/:post'
,
},
},
{
source
:
'/missing-rewrite-1'
,
missing
:
[
{
type
:
'header'
,
key
:
'x-my-header'
,
value
:
'(?<myHeader>.*)'
,
},
],
destination
:
'/with-params'
,
},
{
source
:
'/missing-rewrite-2'
,
missing
:
[
{
type
:
'query'
,
key
:
'my-query'
,
},
],
destination
:
'/with-params'
,
},
{
source
:
'/missing-rewrite-3'
,
missing
:
[
{
type
:
'cookie'
,
key
:
'loggedIn'
,
value
:
'(?<loggedIn>true)'
,
},
],
destination
:
'/with-params?authorized=1'
,
},
{
{
source
:
'/blog/about'
,
source
:
'/blog/about'
,
destination
:
'/hello'
,
destination
:
'/hello'
,
...
...
test/integration/custom-routes/test/index.test.js
View file @
0381cf09
...
@@ -20,7 +20,6 @@ import {
...
@@ -20,7 +20,6 @@ import {
getBrowserBodyText
,
getBrowserBodyText
,
waitFor
,
waitFor
,
normalizeRegEx
,
normalizeRegEx
,
initNextServerScript
,
nextExport
,
nextExport
,
hasRedbox
,
hasRedbox
,
check
,
check
,
...
@@ -914,6 +913,52 @@ const runTests = (isDev = false) => {
...
@@ -914,6 +913,52 @@ const runTests = (isDev = false) => {
)
)
})
})
it
(
'should match missing header rewrite correctly'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
appPort
,
'/missing-rewrite-1'
,
undefined
,
{
headers
:
{
'x-my-header'
:
'hello world!!'
,
},
})
expect
(
res
.
status
).
toBe
(
404
)
const
res2
=
await
fetchViaHTTP
(
appPort
,
'/missing-rewrite-1'
)
const
$2
=
cheerio
.
load
(
await
res2
.
text
())
expect
(
res2
.
status
).
toBe
(
200
)
expect
(
JSON
.
parse
(
$2
(
'#query'
).
text
())).
toEqual
({})
})
it
(
'should match missing query rewrite correctly'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
appPort
,
'/missing-rewrite-2'
,
{
'my-query'
:
'hellooo'
,
})
expect
(
res
.
status
).
toBe
(
404
)
const
res2
=
await
fetchViaHTTP
(
appPort
,
'/missing-rewrite-2'
)
const
$2
=
cheerio
.
load
(
await
res2
.
text
())
expect
(
res2
.
status
).
toBe
(
200
)
expect
(
JSON
.
parse
(
$2
(
'#query'
).
text
())).
toEqual
({})
})
it
(
'should match missing cookie rewrite correctly'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
appPort
,
'/missing-rewrite-3'
,
undefined
,
{
headers
:
{
cookie
:
'loggedIn=true'
,
},
})
expect
(
res
.
status
).
toBe
(
404
)
const
res2
=
await
fetchViaHTTP
(
appPort
,
'/missing-rewrite-3'
)
const
$2
=
cheerio
.
load
(
await
res2
.
text
())
expect
(
JSON
.
parse
(
$2
(
'#query'
).
text
())).
toEqual
({
authorized
:
'1'
,
})
expect
(
res2
.
status
).
toBe
(
200
)
})
it
(
'should match has header rewrite correctly'
,
async
()
=>
{
it
(
'should match has header rewrite correctly'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
appPort
,
'/has-rewrite-1'
,
undefined
,
{
const
res
=
await
fetchViaHTTP
(
appPort
,
'/has-rewrite-1'
,
undefined
,
{
headers
:
{
headers
:
{
...
@@ -2080,6 +2125,41 @@ const runTests = (isDev = false) => {
...
@@ -2080,6 +2125,41 @@ const runTests = (isDev = false) => {
regex
:
normalizeRegEx
(
'^
\\
/has-rewrite-8(?:
\\
/)?$'
),
regex
:
normalizeRegEx
(
'^
\\
/has-rewrite-8(?:
\\
/)?$'
),
source
:
'/has-rewrite-8'
,
source
:
'/has-rewrite-8'
,
},
},
{
destination
:
'/with-params'
,
missing
:
[
{
key
:
'x-my-header'
,
type
:
'header'
,
value
:
'(?<myHeader>.*)'
,
},
],
regex
:
normalizeRegEx
(
'^
\\
/missing-rewrite-1(?:
\\
/)?$'
),
source
:
'/missing-rewrite-1'
,
},
{
destination
:
'/with-params'
,
missing
:
[
{
key
:
'my-query'
,
type
:
'query'
,
},
],
regex
:
normalizeRegEx
(
'^
\\
/missing-rewrite-2(?:
\\
/)?$'
),
source
:
'/missing-rewrite-2'
,
},
{
destination
:
'/with-params?authorized=1'
,
missing
:
[
{
key
:
'loggedIn'
,
type
:
'cookie'
,
value
:
'(?<loggedIn>true)'
,
},
],
regex
:
normalizeRegEx
(
'^
\\
/missing-rewrite-3(?:
\\
/)?$'
),
source
:
'/missing-rewrite-3'
,
},
{
{
destination
:
'/hello'
,
destination
:
'/hello'
,
regex
:
normalizeRegEx
(
'^
\\
/blog
\\
/about(?:
\\
/)?$'
),
regex
:
normalizeRegEx
(
'^
\\
/blog
\\
/about(?:
\\
/)?$'
),
...
@@ -2426,96 +2506,6 @@ describe('Custom routes', () => {
...
@@ -2426,96 +2506,6 @@ describe('Custom routes', () => {
})
})
})
})
describe
(
'serverless mode'
,
()
=>
{
beforeAll
(
async
()
=>
{
nextConfigContent
=
await
fs
.
readFile
(
nextConfigPath
,
'utf8'
)
await
fs
.
writeFile
(
nextConfigPath
,
nextConfigContent
.
replace
(
/
\/\/
target/
,
'target'
),
'utf8'
)
const
{
stdout
:
buildStdout
}
=
await
nextBuild
(
appDir
,
[
'-d'
],
{
stdout
:
true
,
})
stdout
=
buildStdout
appPort
=
await
findPort
()
app
=
await
nextStart
(
appDir
,
appPort
,
{
onStdout
:
(
msg
)
=>
{
stdout
+=
msg
},
})
buildId
=
await
fs
.
readFile
(
join
(
appDir
,
'.next/BUILD_ID'
),
'utf8'
)
})
afterAll
(
async
()
=>
{
await
fs
.
writeFile
(
nextConfigPath
,
nextConfigContent
,
'utf8'
)
await
killApp
(
app
)
})
runTests
()
})
describe
(
'raw serverless mode'
,
()
=>
{
beforeAll
(
async
()
=>
{
nextConfigContent
=
await
fs
.
readFile
(
nextConfigPath
,
'utf8'
)
await
fs
.
writeFile
(
nextConfigPath
,
nextConfigContent
.
replace
(
/
\/\/
target/
,
'target'
),
'utf8'
)
await
nextBuild
(
appDir
)
appPort
=
await
findPort
()
app
=
await
initNextServerScript
(
join
(
appDir
,
'server.js'
),
/ready on/
,
{
...
process
.
env
,
PORT
:
appPort
,
})
})
afterAll
(
async
()
=>
{
await
fs
.
writeFile
(
nextConfigPath
,
nextConfigContent
,
'utf8'
)
await
killApp
(
app
)
})
it
(
'should apply rewrites in lambda correctly for page route'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
appPort
,
'/query-rewrite/first/second'
)
const
data
=
JSON
.
parse
(
cheerio
.
load
(
html
)(
'p'
).
text
())
expect
(
data
).
toEqual
({
first
:
'first'
,
second
:
'second'
,
section
:
'first'
,
name
:
'second'
,
})
})
it
(
'should apply rewrites in lambda correctly for dynamic route'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
appPort
,
'/blog/post-1'
)
expect
(
html
).
toContain
(
'post-2'
)
})
it
(
'should apply rewrites in lambda correctly for API route'
,
async
()
=>
{
const
data
=
JSON
.
parse
(
await
renderViaHTTP
(
appPort
,
'/api-hello-param/first'
)
)
expect
(
data
).
toEqual
({
query
:
{
name
:
'first'
,
hello
:
'first'
,
},
})
})
it
(
'should apply rewrites in lambda correctly for dynamic API route'
,
async
()
=>
{
const
data
=
JSON
.
parse
(
await
renderViaHTTP
(
appPort
,
'/api-dynamic-param/first'
)
)
expect
(
data
).
toEqual
({
query
:
{
slug
:
'first'
,
hello
:
'first'
,
},
})
})
})
describe
(
'should load custom routes when only one type is used'
,
()
=>
{
describe
(
'should load custom routes when only one type is used'
,
()
=>
{
const
runSoloTests
=
(
isDev
)
=>
{
const
runSoloTests
=
(
isDev
)
=>
{
const
buildAndStart
=
async
()
=>
{
const
buildAndStart
=
async
()
=>
{
...
...
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