1
1
import Chance from 'chance'
2
- import { ExperimentalConfig } from 'next/dist/server/config-shared'
3
2
import type { PrerenderManifest } from 'next/dist/build'
4
- import { generateDynamicRewrites } from '../../packages/runtime/src/helpers/redirects '
3
+ import { ExperimentalConfig } from 'next/dist/server/config-shared '
5
4
5
+ import { generateDynamicRewrites } from '../../packages/runtime/src/helpers/redirects'
6
6
import {
7
7
getCustomImageResponseHeaders ,
8
8
getRemotePatterns ,
@@ -20,24 +20,24 @@ const basePrerenderManifest: PrerenderManifest = {
20
20
const prerenderManifest : PrerenderManifest = {
21
21
...basePrerenderManifest ,
22
22
dynamicRoutes : {
23
- " /getStaticProps/[id]" : {
24
- " routeRegex" : " ^/getStaticProps/([^/]+?)(?:/)?$" ,
25
- " dataRoute" : " /_next/data/build-id/getStaticProps/[id].json" ,
26
- " fallback" : false ,
27
- " dataRouteRegex" : " ^/_next/data/build\\-id/getStaticProps/([^/]+?)\\.json$"
28
- } ,
23
+ ' /getStaticProps/[id]' : {
24
+ routeRegex : ' ^/getStaticProps/([^/]+?)(?:/)?$' ,
25
+ dataRoute : ' /_next/data/build-id/getStaticProps/[id].json' ,
26
+ fallback : false ,
27
+ dataRouteRegex : ' ^/_next/data/build\\-id/getStaticProps/([^/]+?)\\.json$' ,
28
+ } ,
29
29
} ,
30
30
}
31
31
32
32
const dynamicRoutes = [
33
33
{
34
- " page" : " /getStaticProps/[id]" ,
35
- " regex" : " ^/getStaticProps/([^/]+?)(?:/)?$" ,
36
- " routeKeys" : {
37
- " nextParamid" : " nextParamid"
34
+ page : ' /getStaticProps/[id]' ,
35
+ regex : ' ^/getStaticProps/([^/]+?)(?:/)?$' ,
36
+ routeKeys : {
37
+ nextParamid : ' nextParamid' ,
38
38
} ,
39
- " namedRegex" : " ^/getStaticProps/(?<nextParamid>[^/]+?)(?:/)?$"
40
- } ,
39
+ namedRegex : ' ^/getStaticProps/(?<nextParamid>[^/]+?)(?:/)?$' ,
40
+ } ,
41
41
]
42
42
43
43
const route = {
@@ -176,23 +176,22 @@ describe('redirectsForNext404Route', () => {
176
176
} )
177
177
178
178
it ( 'returns static 404 redirects when LEGACY_FALLBACK_FALSE is not set' , async ( ) => {
179
-
180
179
const expected = {
181
- " dynamicRewrites" : [
180
+ dynamicRewrites : [
182
181
{
183
- " force" : false ,
184
- " from" : " /_next/data/test/getStaticProps/:id.json" ,
185
- " status" : 404 ,
186
- "to" : " /server/pages/404.html" ,
187
- } ,
182
+ force : false ,
183
+ from : ' /_next/data/test/getStaticProps/:id.json' ,
184
+ status : 404 ,
185
+ to : ' /server/pages/404.html' ,
186
+ } ,
188
187
{
189
- " force" : false ,
190
- " from" : " /getStaticProps/:id" ,
191
- " status" : 404 ,
192
- "to" : " /server/pages/404.html" ,
193
- }
194
- ] ,
195
- " dynamicRoutesThatMatchMiddleware" : [ ]
188
+ force : false ,
189
+ from : ' /getStaticProps/:id' ,
190
+ status : 404 ,
191
+ to : ' /server/pages/404.html' ,
192
+ } ,
193
+ ] ,
194
+ dynamicRoutesThatMatchMiddleware : [ ] ,
196
195
}
197
196
198
197
expect ( generateDynamicRewrites ( route ) ) . toStrictEqual ( expected )
@@ -202,21 +201,21 @@ describe('redirectsForNext404Route', () => {
202
201
process . env . LEGACY_FALLBACK_FALSE = 'true'
203
202
204
203
const expected = {
205
- " dynamicRewrites" : [
204
+ dynamicRewrites : [
206
205
{
207
- " force" : false ,
208
- " from" : " /_next/data/test/getStaticProps/:id.json" ,
209
- " status" : 200 ,
210
- "to" : " /.netlify/builders/___netlify-odb-handler" ,
211
- } ,
206
+ force : false ,
207
+ from : ' /_next/data/test/getStaticProps/:id.json' ,
208
+ status : 200 ,
209
+ to : ' /.netlify/builders/___netlify-odb-handler' ,
210
+ } ,
212
211
{
213
- " force" : false ,
214
- " from" : " /getStaticProps/:id" ,
215
- " status" : 200 ,
216
- "to" : " /.netlify/builders/___netlify-odb-handler" ,
217
- }
218
- ] ,
219
- " dynamicRoutesThatMatchMiddleware" : [ ]
212
+ force : false ,
213
+ from : ' /getStaticProps/:id' ,
214
+ status : 200 ,
215
+ to : ' /.netlify/builders/___netlify-odb-handler' ,
216
+ } ,
217
+ ] ,
218
+ dynamicRoutesThatMatchMiddleware : [ ] ,
220
219
}
221
220
222
221
expect ( generateDynamicRewrites ( route ) ) . toStrictEqual ( expected )
@@ -225,27 +224,25 @@ describe('redirectsForNext404Route', () => {
225
224
it ( 'returns static 404 redirects when LEGACY_FALLBACK_FALSE is set as "false"' , async ( ) => {
226
225
// testing to make sure that the any other string other than 'true' still returns the static 404 redirects
227
226
process . env . LEGACY_FALLBACK_FALSE = 'false'
228
-
227
+
229
228
const expected = {
230
- " dynamicRewrites" : [
229
+ dynamicRewrites : [
231
230
{
232
- " force" : false ,
233
- " from" : " /_next/data/test/getStaticProps/:id.json" ,
234
- " status" : 404 ,
235
- "to" : " /server/pages/404.html" ,
236
- } ,
231
+ force : false ,
232
+ from : ' /_next/data/test/getStaticProps/:id.json' ,
233
+ status : 404 ,
234
+ to : ' /server/pages/404.html' ,
235
+ } ,
237
236
{
238
- " force" : false ,
239
- " from" : " /getStaticProps/:id" ,
240
- " status" : 404 ,
241
- "to" : " /server/pages/404.html" ,
242
- }
243
- ] ,
244
- " dynamicRoutesThatMatchMiddleware" : [ ]
237
+ force : false ,
238
+ from : ' /getStaticProps/:id' ,
239
+ status : 404 ,
240
+ to : ' /server/pages/404.html' ,
241
+ } ,
242
+ ] ,
243
+ dynamicRoutesThatMatchMiddleware : [ ] ,
245
244
}
246
-
245
+
247
246
expect ( generateDynamicRewrites ( route ) ) . toStrictEqual ( expected )
248
247
} )
249
248
} )
250
-
251
-
0 commit comments