-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
32 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,35 @@ | ||
import { NextResponse } from 'next/server' | ||
import type { NextRequest } from 'next/server' | ||
|
||
export function middleware(request: NextRequest) { | ||
// Only handle requests to /api/skip/* | ||
if (!request.nextUrl.pathname.startsWith('/api/skip/')) { | ||
return NextResponse.next() | ||
} | ||
|
||
// Transform the request URL from /api/skip/* to go.skip.build/api/skip/* | ||
const skipUrl = new URL(request.nextUrl.pathname.replace('/api/skip/', '/api/skip/'), 'https://go.skip.build') | ||
skipUrl.search = request.nextUrl.search // Preserve query parameters | ||
|
||
// Forward the request to Skip API | ||
return NextResponse.rewrite(skipUrl, { | ||
request: { | ||
// Forward headers | ||
headers: new Headers({ | ||
'Content-Type': 'application/json', | ||
// Add any other required headers | ||
}) | ||
} | ||
import { NextRequest } from 'next/server' | ||
|
||
export async function GET(request: NextRequest, { params }: { params: { path?: string[] } }) { | ||
const path = params.path?.join('/') || '' | ||
const { searchParams } = new URL(request.url) | ||
|
||
const skipUrl = `https://go.skip.build/api/skip/${path}${searchParams.toString() ? '?' + searchParams.toString() : ''}` | ||
|
||
const response = await fetch(skipUrl, { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}) | ||
|
||
return response | ||
} | ||
|
||
export async function POST(request: NextRequest, { params }: { params: { path?: string[] } }) { | ||
const path = params.path?.join('/') || '' | ||
const { searchParams } = new URL(request.url) | ||
|
||
const skipUrl = `https://go.skip.build/api/skip/${path}${searchParams.toString() ? '?' + searchParams.toString() : ''}` | ||
|
||
const response = await fetch(skipUrl, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(await request.json()), | ||
}) | ||
|
||
return response | ||
} | ||
|
||
export const config = { | ||
matcher: '/api/skip/:path*', // Only match /api/skip routes | ||
} | ||
// Add other methods (PUT, DELETE, etc.) as needed |