the cleanup
This commit is contained in:
+1
-1
@@ -4,7 +4,7 @@ import { useMemo } from "react";
|
||||
import { useAuth } from "@/context/AuthContext";
|
||||
|
||||
const API_BASE_URL =
|
||||
process.env.NEXT_PUBLIC_API_BASE_URL ?? "http://localhost:8080";
|
||||
process.env.NEXT_PUBLIC_API_BASE_URL ?? "";
|
||||
|
||||
type JsonValue = any;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// lib/api/adminCategoryMappings.ts
|
||||
|
||||
const API_BASE =
|
||||
process.env.NEXT_PUBLIC_API_BASE_URL ?? "http://localhost:8080";
|
||||
process.env.NEXT_PUBLIC_API_BASE_URL ?? "";
|
||||
|
||||
export interface AdminCategory {
|
||||
id: number;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const API_BASE =
|
||||
process.env.NEXT_PUBLIC_API_URL ?? "http://localhost:8080";
|
||||
process.env.NEXT_PUBLIC_API_URL ?? "";
|
||||
|
||||
export interface AdminMerchantCategoryMapping {
|
||||
id: number;
|
||||
|
||||
@@ -17,7 +17,7 @@ export interface UpdateEmailRequestDto {
|
||||
status?: string;
|
||||
}
|
||||
|
||||
const API_BASE = process.env.NEXT_PUBLIC_API_BASE_URL || 'http://localhost:8080';
|
||||
const API_BASE = process.env.NEXT_PUBLIC_API_BASE_URL || '';
|
||||
|
||||
export async function fetchEmailRequests(token: string): Promise<EmailRequest[]> {
|
||||
const response = await fetch(`${API_BASE}/api/email`, {
|
||||
|
||||
@@ -15,7 +15,7 @@ export type CreatePlatformDto = {
|
||||
export type UpdatePlatformDto = Partial<CreatePlatformDto>;
|
||||
|
||||
const API_BASE =
|
||||
process.env.NEXT_PUBLIC_API_BASE_URL ?? "http://localhost:8080";
|
||||
process.env.NEXT_PUBLIC_API_BASE_URL ?? "";
|
||||
|
||||
function normalizePlatform(raw: any): Platform {
|
||||
const id = Number(raw?.id);
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
// lib/auth-client.ts
|
||||
|
||||
const API_BASE_URL =
|
||||
process.env.NEXT_PUBLIC_API_BASE_URL ?? "http://localhost:8080";
|
||||
process.env.NEXT_PUBLIC_API_BASE_URL ?? "";
|
||||
|
||||
export type AuthUser = {
|
||||
id: number;
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
// app/lib/catalog.ts
|
||||
export const API_BASE_URL =
|
||||
process.env.NEXT_PUBLIC_API_BASE_URL ?? "http://localhost:8080";
|
||||
process.env.NEXT_PUBLIC_API_BASE_URL ?? "";
|
||||
|
||||
export type ProductListItem = {
|
||||
id: string;
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
// Central place for app-wide constant values.
|
||||
|
||||
// Branding / product
|
||||
export const APP_NAME = "Ballistic Builder";
|
||||
export const APP_NAME = "Battl Builder";
|
||||
export const APP_TAGLINE = "A smarter way to explore and assemble builds.";
|
||||
|
||||
// URLs
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
const SPRING_BASE =
|
||||
process.env.SPRING_BASE_URL ?? "http://battlbuilder-api:8080";
|
||||
|
||||
function forwardHeaders(req: Request) {
|
||||
const headers = new Headers();
|
||||
const auth = req.headers.get("authorization");
|
||||
const cookie = req.headers.get("cookie");
|
||||
|
||||
if (auth) headers.set("authorization", auth);
|
||||
if (cookie) headers.set("cookie", cookie);
|
||||
|
||||
headers.set("accept", "application/json");
|
||||
return headers;
|
||||
}
|
||||
|
||||
type SpringProxyOptions<TBody> = {
|
||||
method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
||||
body?: TBody;
|
||||
cache?: RequestCache;
|
||||
};
|
||||
|
||||
export async function springProxy<TResponse, TBody = never>(
|
||||
req: Request,
|
||||
path: string,
|
||||
options?: SpringProxyOptions<TBody>
|
||||
) {
|
||||
const url = `${SPRING_BASE}${path}`;
|
||||
const headers = forwardHeaders(req);
|
||||
|
||||
const init: RequestInit = {
|
||||
method: options?.method ?? "GET",
|
||||
headers,
|
||||
cache: options?.cache ?? "no-store",
|
||||
};
|
||||
|
||||
if (options && "body" in options && options.body !== undefined) {
|
||||
headers.set("content-type", "application/json");
|
||||
init.body = JSON.stringify(options.body);
|
||||
}
|
||||
|
||||
const res = await fetch(url, init);
|
||||
|
||||
// If Spring returns 204 No Content, don't try to parse JSON
|
||||
if (res.status === 204) {
|
||||
return new NextResponse(null, { status: 204 });
|
||||
}
|
||||
|
||||
const contentType = res.headers.get("content-type") ?? "";
|
||||
let payload: unknown;
|
||||
|
||||
if (contentType.includes("application/json")) {
|
||||
payload = await res.json().catch(() => null);
|
||||
} else {
|
||||
payload = await res.text().catch(() => null);
|
||||
}
|
||||
|
||||
// If Spring returned JSON, we respond JSON; otherwise text
|
||||
if (typeof payload === "string") {
|
||||
return new NextResponse(payload, {
|
||||
status: res.status,
|
||||
headers: { "content-type": contentType || "text/plain" },
|
||||
});
|
||||
}
|
||||
|
||||
return NextResponse.json(payload as TResponse, { status: res.status });
|
||||
}
|
||||
+1
-1
@@ -4,7 +4,7 @@ import { useAuth } from "@/context/AuthContext";
|
||||
import { useCallback, useMemo } from "react";
|
||||
|
||||
const DEFAULT_API_BASE =
|
||||
process.env.NEXT_PUBLIC_API_BASE_URL ?? "http://localhost:8080";
|
||||
process.env.NEXT_PUBLIC_API_BASE_URL ?? "";
|
||||
|
||||
export function useApi(baseUrl: string = DEFAULT_API_BASE) {
|
||||
const { token } = useAuth();
|
||||
|
||||
Reference in New Issue
Block a user