Skip to content

Commit 4976656

Browse files
Apply middleware to all api routes (#451)
* Initial draft * do a dirty rewrite for query params
1 parent 4ba61ab commit 4976656

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

app/api/all-docs-paths/route.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ import { PRODUCT_CONFIG } from '@utils/productConfig.mjs'
1010
export async function GET(req: Request) {
1111
const url = new URL(req.url)
1212
const productSlugs = url.searchParams.getAll('products')
13+
14+
const index = productSlugs.indexOf('ptfe-releases')
15+
if (index !== -1) {
16+
productSlugs[index] = 'terraform-enterprise'
17+
}
18+
1319
const docsPaths = await getDocsPaths(
1420
productSlugs.length === 0 ? Object.keys(PRODUCT_CONFIG) : productSlugs,
1521
)

app/api/content-versions/route.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ import { PRODUCT_CONFIG } from '@utils/productConfig.mjs'
88

99
export async function GET(request: Request) {
1010
const url = new URL(request.url)
11-
const product = url.searchParams.get('product')
11+
let product = url.searchParams.get('product')
1212
const fullPath = url.searchParams.get('fullPath')
1313

14+
if (product === 'ptfe-releases') {
15+
product = 'terraform-enterprise'
16+
}
17+
1418
// If a `product` parameter has not been provided, return a 400
1519
if (!product) {
1620
return new Response(

middleware.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,8 @@ export function middleware({ url }) {
2323
}
2424

2525
export const config = {
26-
matcher: '/api/content/ptfe-releases/:path*',
26+
matcher: [
27+
'/api/content/ptfe-releases/:path*',
28+
'/api/assets/ptfe-releases/:path*',
29+
],
2730
}

0 commit comments

Comments
 (0)