-
Notifications
You must be signed in to change notification settings - Fork 178
/
middleware.ts
31 lines (25 loc) · 934 Bytes
/
middleware.ts
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 { NextFetchEvent, NextRequest, NextResponse } from 'next/server';
import CompletionsMiddleware from './lib/middleware/completions';
import AppMiddleware from './lib/middleware/app';
import { getHost } from './lib/utils';
import TrainMiddleware from './lib/middleware/train';
export const config = {
matcher: [
'/((?!_next/|_proxy/|_auth/|_root/|_static|static|_vercel|[\\w-]+\\.\\w+).*)',
],
};
export default async function middleware(req: NextRequest, ev: NextFetchEvent) {
const hostname = req.headers.get('host');
if (hostname === getHost()) {
return AppMiddleware(req);
}
if (hostname === 'api.markprompt.com' || hostname === 'api.localhost:3000') {
const path = req.nextUrl.pathname;
if (path?.startsWith('/completions')) {
return CompletionsMiddleware(req);
} else if (path?.startsWith('/train')) {
return TrainMiddleware(req);
}
}
return NextResponse.next();
}