forked from ChatGPTNextWeb/ChatGPT-Next-Web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/Yidadaa/ChatGPT-Next-Web
- Loading branch information
Showing
17 changed files
with
629 additions
and
103 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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { NextRequest, NextResponse } from "next/server"; | ||
|
||
async function handle( | ||
req: NextRequest, | ||
{ params }: { params: { path: string[] } }, | ||
) { | ||
if (req.method === "OPTIONS") { | ||
return NextResponse.json({ body: "OK" }, { status: 200 }); | ||
} | ||
|
||
const [protocol, ...subpath] = params.path; | ||
const targetUrl = `${protocol}://${subpath.join("/")}`; | ||
|
||
const method = req.headers.get("method") ?? undefined; | ||
const shouldNotHaveBody = ["get", "head"].includes( | ||
method?.toLowerCase() ?? "", | ||
); | ||
|
||
const fetchOptions: RequestInit = { | ||
headers: { | ||
authorization: req.headers.get("authorization") ?? "", | ||
}, | ||
body: shouldNotHaveBody ? null : req.body, | ||
method, | ||
// @ts-ignore | ||
duplex: "half", | ||
}; | ||
|
||
console.log("[Any Proxy]", targetUrl); | ||
|
||
const fetchResult = fetch(targetUrl, fetchOptions); | ||
|
||
return fetchResult; | ||
} | ||
|
||
export const POST = handle; | ||
|
||
export const runtime = "edge"; |
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
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
Oops, something went wrong.