-
Notifications
You must be signed in to change notification settings - Fork 0
Phase:2- Refactoring #91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
19dc7bc
feat(*): phase-2 refactoring
Ayush8923 65dd616
fix(*): use the apiClient function in the route file
Ayush8923 03be161
fix(*): update the AuthContext
Ayush8923 d65760e
Merge branch 'feat/refactor-routes-phase-1' of https://github.com/Pro…
Ayush8923 022d2b7
merge conflicts resolve
Ayush8923 8a63136
fix(*): update the import alias
Ayush8923 1d1c1d3
fix(*): fix the local storage hydrate issue
Ayush8923 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,49 +1,28 @@ | ||
| import { NextRequest, NextResponse } from 'next/server'; | ||
|
|
||
| import { apiClient } from "@/app/lib/apiClient"; | ||
| import { NextRequest, NextResponse } from "next/server"; | ||
|
|
||
| export async function POST(request: NextRequest) { | ||
| try { | ||
| // Get the API key from request headers | ||
| const apiKey = request.headers.get('X-API-KEY'); | ||
|
|
||
| if (!apiKey) { | ||
| return NextResponse.json( | ||
| { error: 'Missing X-API-KEY header' }, | ||
| { status: 401 } | ||
| ); | ||
| } | ||
|
|
||
| // Get the form data from the request | ||
| const formData = await request.formData(); | ||
|
|
||
| // Get backend URL from environment variable | ||
| const backendUrl = process.env.BACKEND_URL || 'http://localhost:8000'; | ||
|
|
||
| // Forward the request to the actual backend | ||
| const response = await fetch(`${backendUrl}/api/v1/evaluations/stt/files`, { | ||
| method: 'POST', | ||
| body: formData, | ||
| headers: { | ||
| 'X-API-KEY': apiKey, | ||
|
|
||
| const { status, data: responseData } = await apiClient( | ||
| request, | ||
| "/api/v1/evaluations/stt/files", | ||
| { | ||
| method: "POST", | ||
| body: formData, | ||
| }, | ||
| }); | ||
|
|
||
| // Handle empty responses (204 No Content, etc.) | ||
| const text = await response.text(); | ||
| const data = text ? JSON.parse(text) : { success: true }; | ||
|
|
||
| // Return the response with the same status code | ||
| if (!response.ok) { | ||
| return NextResponse.json(data, { status: response.status }); | ||
| } | ||
| ); | ||
|
|
||
| return NextResponse.json(data, { status: response.status }); | ||
| return NextResponse.json(responseData, { status }); | ||
| } catch (error: unknown) { | ||
| console.error('Proxy error:', error); | ||
| console.error("Proxy error:", error); | ||
| return NextResponse.json( | ||
| { error: 'Failed to forward request to backend', details: error instanceof Error ? error.message : String(error) }, | ||
| { status: 500 } | ||
| { | ||
| error: "Failed to forward request to backend", | ||
| details: error instanceof Error ? error.message : String(error), | ||
| }, | ||
| { status: 500 }, | ||
| ); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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,53 +1,41 @@ | ||
| import { NextResponse, NextRequest } from 'next/server'; | ||
| import { apiClient } from "@/app/lib/apiClient"; | ||
| import { NextResponse, NextRequest } from "next/server"; | ||
|
|
||
| export async function GET(request: Request) { | ||
| const backendUrl = process.env.BACKEND_URL || 'http://localhost:8000'; | ||
| const apiKey = request.headers.get('X-API-KEY'); | ||
|
|
||
| try { | ||
| const response = await fetch(`${backendUrl}/api/v1/evaluations/tts/datasets`, { | ||
| headers: { | ||
| 'X-API-KEY': apiKey || '', | ||
| }, | ||
| }); | ||
|
|
||
| const data = await response.json(); | ||
| return NextResponse.json(data, { status: response.status }); | ||
| const { status, data } = await apiClient( | ||
| request, | ||
| "/api/v1/evaluations/tts/datasets", | ||
| ); | ||
| return NextResponse.json(data, { status }); | ||
| } catch (error) { | ||
| return NextResponse.json( | ||
| { success: false, error: error, data: null }, | ||
| { status: 500 } | ||
| { status: 500 }, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| export async function POST(request: NextRequest) { | ||
| try { | ||
| const apiKey = request.headers.get('X-API-KEY'); | ||
| if (!apiKey) { | ||
| return NextResponse.json( | ||
| { error: 'Missing X-API-KEY. Either generate an API Key. Contact Kaapi team for more details' }, | ||
| { status: 401 } | ||
| ); | ||
| } | ||
| const body = await request.json(); | ||
| const backendUrl = process.env.BACKEND_URL || 'http://localhost:8000'; | ||
|
|
||
| const response = await fetch(`${backendUrl}/api/v1/evaluations/tts/datasets`, { | ||
| method: 'POST', | ||
| body: JSON.stringify(body), | ||
| headers: { | ||
| 'X-API-KEY': apiKey, | ||
| 'Content-Type': 'application/json', | ||
| const { status, data } = await apiClient( | ||
| request, | ||
| "/api/v1/evaluations/tts/datasets", | ||
| { | ||
| method: "POST", | ||
| body: JSON.stringify(body), | ||
| }, | ||
| }); | ||
| const data = await response.json(); | ||
| return NextResponse.json(data, { status: response.status }); | ||
| ); | ||
| return NextResponse.json(data, { status }); | ||
| } catch (error) { | ||
| console.error('Proxy error:', error); | ||
| console.error("Proxy error:", error); | ||
| return NextResponse.json( | ||
| { error: 'Failed to forward request to backend', details: error instanceof Error ? error.message : String(error) }, | ||
| { status: 500 } | ||
| { | ||
| error: "Failed to forward request to backend", | ||
| details: error instanceof Error ? error.message : String(error), | ||
| }, | ||
| { status: 500 }, | ||
| ); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.