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 pull request ChatGPTNextWeb#2819 from Yidadaa/webdav
- Loading branch information
Showing
15 changed files
with
623 additions
and
101 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.