amalsp commited on
Commit
961393a
·
1 Parent(s): eac1b7b

Replace API rewrites with route handlers for stable proxying

Browse files
app/api/export/cover-letter/[format]/route.ts ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const backendApiUrl = process.env.BACKEND_API_URL || "http://127.0.0.1:8000";
2
+
3
+ export async function POST(
4
+ request: Request,
5
+ { params }: { params: Promise<{ format: string }> },
6
+ ) {
7
+ const { format } = await params;
8
+ const body = await request.text();
9
+
10
+ const response = await fetch(`${backendApiUrl}/api/export/cover-letter/${format}`, {
11
+ method: "POST",
12
+ headers: {
13
+ "Content-Type": request.headers.get("content-type") || "application/json",
14
+ },
15
+ body,
16
+ });
17
+
18
+ return new Response(await response.arrayBuffer(), {
19
+ status: response.status,
20
+ headers: {
21
+ "Content-Type":
22
+ response.headers.get("content-type") || "application/octet-stream",
23
+ "Content-Disposition":
24
+ response.headers.get("content-disposition") ||
25
+ `attachment; filename="cover-letter.${format}"`,
26
+ },
27
+ });
28
+ }
app/api/export/resume/[format]/route.ts ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const backendApiUrl = process.env.BACKEND_API_URL || "http://127.0.0.1:8000";
2
+
3
+ export async function POST(
4
+ request: Request,
5
+ { params }: { params: Promise<{ format: string }> },
6
+ ) {
7
+ const { format } = await params;
8
+ const body = await request.text();
9
+
10
+ const response = await fetch(`${backendApiUrl}/api/export/resume/${format}`, {
11
+ method: "POST",
12
+ headers: {
13
+ "Content-Type": request.headers.get("content-type") || "application/json",
14
+ },
15
+ body,
16
+ });
17
+
18
+ return new Response(await response.arrayBuffer(), {
19
+ status: response.status,
20
+ headers: {
21
+ "Content-Type":
22
+ response.headers.get("content-type") || "application/octet-stream",
23
+ "Content-Disposition":
24
+ response.headers.get("content-disposition") ||
25
+ `attachment; filename="optimized-resume.${format}"`,
26
+ },
27
+ });
28
+ }
app/api/healthz/route.ts ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const backendApiUrl = process.env.BACKEND_API_URL || "http://127.0.0.1:8000";
2
+
3
+ export async function GET() {
4
+ const response = await fetch(`${backendApiUrl}/health`, {
5
+ cache: "no-store",
6
+ });
7
+
8
+ return new Response(await response.text(), {
9
+ status: response.status,
10
+ headers: {
11
+ "Content-Type": response.headers.get("content-type") || "application/json",
12
+ },
13
+ });
14
+ }
app/api/pipeline/route.ts ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const backendApiUrl = process.env.BACKEND_API_URL || "http://127.0.0.1:8000";
2
+
3
+ export async function POST(request: Request) {
4
+ const body = await request.text();
5
+
6
+ const response = await fetch(`${backendApiUrl}/api/pipeline`, {
7
+ method: "POST",
8
+ headers: {
9
+ "Content-Type": request.headers.get("content-type") || "application/json",
10
+ },
11
+ body,
12
+ });
13
+
14
+ return new Response(await response.text(), {
15
+ status: response.status,
16
+ headers: {
17
+ "Content-Type": response.headers.get("content-type") || "application/json",
18
+ },
19
+ });
20
+ }
app/api/pipeline/upload/route.ts ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const backendApiUrl = process.env.BACKEND_API_URL || "http://127.0.0.1:8000";
2
+
3
+ export async function POST(request: Request) {
4
+ const incoming = await request.formData();
5
+ const formData = new FormData();
6
+
7
+ for (const [key, value] of incoming.entries()) {
8
+ formData.append(key, value);
9
+ }
10
+
11
+ const response = await fetch(`${backendApiUrl}/api/pipeline/upload`, {
12
+ method: "POST",
13
+ body: formData,
14
+ });
15
+
16
+ return new Response(await response.text(), {
17
+ status: response.status,
18
+ headers: {
19
+ "Content-Type": response.headers.get("content-type") || "application/json",
20
+ },
21
+ });
22
+ }
next.config.ts CHANGED
@@ -1,22 +1,8 @@
1
  import type { NextConfig } from "next";
2
 
3
- const backendApiUrl = process.env.BACKEND_API_URL || "http://127.0.0.1:8000";
4
-
5
  const nextConfig: NextConfig = {
6
  reactStrictMode: true,
7
  output: "standalone",
8
- async rewrites() {
9
- return [
10
- {
11
- source: "/api/:path*",
12
- destination: `${backendApiUrl}/api/:path*`,
13
- },
14
- {
15
- source: "/healthz",
16
- destination: `${backendApiUrl}/health`,
17
- },
18
- ];
19
- },
20
  };
21
 
22
  export default nextConfig;
 
1
  import type { NextConfig } from "next";
2
 
 
 
3
  const nextConfig: NextConfig = {
4
  reactStrictMode: true,
5
  output: "standalone",
 
 
 
 
 
 
 
 
 
 
 
 
6
  };
7
 
8
  export default nextConfig;