forked from Anil-matcha/Open-Generative-AI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.js
More file actions
31 lines (26 loc) · 1019 Bytes
/
middleware.js
File metadata and controls
31 lines (26 loc) · 1019 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { NextResponse } from 'next/server';
export function middleware(request) {
const url = request.nextUrl;
// Catch requests to /api/workflow, /api/app, and /api/v1
const isMuApi = url.pathname.startsWith('/api/workflow') ||
url.pathname.startsWith('/api/app') ||
url.pathname.startsWith('/api/v1');
if (isMuApi) {
// Remap /api/v1 ONLY if it's not handled by a specific route.
// Actually, we'll let existing remapping for /api/v1 stay if needed,
// but we'll remove app/workflow as they need special handling.
if (url.pathname.startsWith('/api/v1')) {
const targetUrl = new URL(url.pathname + url.search, 'https://api.muapi.ai');
return NextResponse.rewrite(targetUrl);
}
}
return NextResponse.next();
}
// Match the paths we want to proxy
export const config = {
matcher: [
'/api/workflow/:path*',
'/api/app/:path*',
'/api/v1/:path*'
],
};