Skip to content

Commit

Permalink
fix: fix ssl version error (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
UNICKCHENG committed Aug 12, 2023
1 parent 8f94b7a commit 7f47c81
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ export async function POST(
) {
const { messages, stream = false } = await request.json();
const init: RequestInit = claude.openaiToClaudeRequest(messages, params.org_id, params.conversation_id);
const url = new URL(request.url);
url.protocol = url.host.includes('localhost') ? 'http:' : 'https:';
const response = await fetch(new URL('/api/claude/append_message', url), init);
const response = await fetch(new URL('/api/claude/append_message', request.url), init);

if (!response.ok) {
return new Response(response.body, { status: 400 })
Expand Down
4 changes: 1 addition & 3 deletions app/api/claude/[org_id]/v1/chat/completions/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ export async function POST(
const { messages, stream = false } = await request.json();
const conversation_uuid = await claude.autoGetConversationId(params.org_id, request.url);
const init: RequestInit = claude.openaiToClaudeRequest(messages, params.org_id, conversation_uuid);
const url = new URL(request.url);
url.protocol = url.host.includes('localhost') ? 'http:' : 'https:';
const response = await fetch(new URL('/api/claude/append_message', url), init);
const response = await fetch(new URL('/api/claude/append_message', request.url), init);

if (!response.ok) {
return new Response(response.body, { status: 400 })
Expand Down
3 changes: 3 additions & 0 deletions middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export async function middleware(
request: NextRequest,
event: NextFetchEvent
): Promise<Response | undefined> {
// 解决反代时,https://localhost 导致 https ssl 证书错误
const regex = new RegExp('localhost|127\.0\.0\.1');
request.nextUrl.protocol = regex.test(request.nextUrl.hostname) ? 'http:' : request.nextUrl.protocol;

if ('OPTIONS' == request.method) {
return new Response(null, { status: 200, headers: corsHeaders });
Expand Down

0 comments on commit 7f47c81

Please sign in to comment.