Skip to content

Commit fe6ca5f

Browse files
committed
middleware + fully static workaround
1 parent befe21a commit fe6ca5f

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/adapter/build/routing.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,19 @@ export async function generateRoutingRules(
113113
// })
114114
// }
115115
}
116+
117+
// TODO: this seems wrong in Next.js (?)
118+
if (
119+
dynamicRoute.sourceRegex.includes('_next/data') &&
120+
!dynamicRoute.destination.includes('/_next/data')
121+
) {
122+
console.log(
123+
'Skipping dynamic route because source care about next/data while destination does not',
124+
dynamicRoute,
125+
)
126+
continue
127+
}
128+
116129
dynamicRoutes.push(
117130
convertDynamicRouteToRoutingRule(
118131
dynamicRoute,
@@ -523,6 +536,7 @@ export async function generateRoutingRules(
523536
},
524537
},
525538
continue: true,
539+
override: true,
526540
} satisfies RoutingRuleApply,
527541
{
528542
// apply __next_data_catchall rewrite

src/adapter/run/routing.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ type RoutingRuleBase = {
2121
description: string
2222
/** if we should keep going even if we already have potential response */
2323
continue?: true
24+
/** this will allow to evaluate route even if previous route was matched and didn't have continue: true */
25+
override?: true
2426
}
2527

2628
type Match = {
@@ -142,12 +144,20 @@ async function match(
142144
let currentRequest = request
143145
let maybeResponse: MaybeResponse = initialResponse
144146

147+
let onlyOverrides = false
148+
145149
return tracer.withActiveSpan(spanName, async (span) => {
146150
for (const rule of routingRules) {
147151
const currentURL = new URL(currentRequest.url)
148152
const { pathname } = currentURL
149153

150154
const desc = rule.description ?? JSON.stringify(rule)
155+
156+
if (onlyOverrides && !rule.override) {
157+
log('Skipping rule because there is a match and this is not override:', desc, pathname)
158+
continue
159+
}
160+
151161
// eslint-disable-next-line no-loop-func
152162
const result = await tracer.withActiveSpan(desc, async (span) => {
153163
log('Evaluating rule:', desc, pathname)
@@ -472,18 +482,19 @@ async function match(
472482
}
473483

474484
if (matched && !shouldContinueOnMatch) {
485+
onlyOverrides = true
475486
// once hit a match short circuit, unless we should continue
476-
return { maybeResponse, currentRequest }
487+
// return { maybeResponse, currentRequest }
477488
}
478489

479490
if (!matched) {
480491
span.setStatus({ code: SpanStatusCode.ERROR, message: 'Miss' })
481492
}
482493
})
483494

484-
if (result) {
485-
return result
486-
}
495+
// if (result) {
496+
// return result
497+
// }
487498
}
488499
return { maybeResponse, currentRequest }
489500
})

0 commit comments

Comments
 (0)