Skip to content

Commit 025c581

Browse files
committed
api server url env cleanup (#4887)
## Problem solved Short description of the bug fixed or feature added <!-- start pr-codex --> --- ## PR-Codex overview This PR introduces a new constant, `API_SERVER_URL`, to centralize the API server URL configuration. It replaces instances of `process.env.NEXT_PUBLIC_THIRDWEB_API_HOST` throughout the codebase, enhancing maintainability and readability. ### Detailed summary - Added `API_SERVER_URL` in `env.ts`. - Replaced `process.env.NEXT_PUBLIC_THIRDWEB_API_HOST` with `API_SERVER_URL` in multiple files: - `getAccount.ts` - `fetchEcosystemList.ts` - `fetchEcosystem.ts` - `team-members.ts` - `get-auth-token/route.ts` - `getAPIKeys.ts` - `ensure-login/route.ts` - `server-proxy/api/[...paths].tsx` - `team.ts` - `projects.ts` - `create-ticket.action.ts` - `auth-actions.ts` - `utils.ts` - Updated fetch requests to use `API_SERVER_URL` for consistent API endpoint access. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 522968a commit 025c581

File tree

14 files changed

+51
-71
lines changed

14 files changed

+51
-71
lines changed

apps/dashboard/src/@/api/projects.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import "server-only";
22
import { COOKIE_ACTIVE_ACCOUNT, COOKIE_PREFIX_TOKEN } from "@/constants/cookie";
3+
import { API_SERVER_URL } from "@/constants/env";
34
import { cookies } from "next/headers";
45

5-
const THIRDWEB_API_HOST =
6-
process.env.NEXT_PUBLIC_THIRDWEB_API_HOST || "https://api.thirdweb.com";
7-
86
export type Project = {
97
id: string;
108
name: string;
@@ -34,7 +32,7 @@ export async function getProjects(teamSlug: string) {
3432
}
3533

3634
const teamsRes = await fetch(
37-
`${THIRDWEB_API_HOST}/v1/teams/${teamSlug}/projects`,
35+
`${API_SERVER_URL}/v1/teams/${teamSlug}/projects`,
3836
{
3937
headers: {
4038
Authorization: `Bearer ${token}`,
@@ -59,7 +57,7 @@ export async function getProject(teamSlug: string, projectSlug: string) {
5957
}
6058

6159
const teamsRes = await fetch(
62-
`${THIRDWEB_API_HOST}/v1/teams/${teamSlug}/projects/${projectSlug}`,
60+
`${API_SERVER_URL}/v1/teams/${teamSlug}/projects/${projectSlug}`,
6361
{
6462
headers: {
6563
Authorization: `Bearer ${token}`,

apps/dashboard/src/@/api/team-members.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import "server-only";
22
import { COOKIE_ACTIVE_ACCOUNT, COOKIE_PREFIX_TOKEN } from "@/constants/cookie";
3+
import { API_SERVER_URL } from "@/constants/env";
34
import { cookies } from "next/headers";
45

5-
const THIRDWEB_API_HOST =
6-
process.env.NEXT_PUBLIC_THIRDWEB_API_HOST || "https://api.thirdweb.com";
7-
86
const TeamAccountRole = {
97
OWNER: "OWNER",
108
MEMBER: "MEMBER",
@@ -39,7 +37,7 @@ export async function getMembers(teamSlug: string) {
3937
}
4038

4139
const teamsRes = await fetch(
42-
`${THIRDWEB_API_HOST}/v1/teams/${teamSlug}/members`,
40+
`${API_SERVER_URL}/v1/teams/${teamSlug}/members`,
4341
{
4442
headers: {
4543
Authorization: `Bearer ${token}`,

apps/dashboard/src/@/api/team.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import "server-only";
22
import { COOKIE_ACTIVE_ACCOUNT, COOKIE_PREFIX_TOKEN } from "@/constants/cookie";
3+
import { API_SERVER_URL } from "@/constants/env";
34
import { cookies } from "next/headers";
45

5-
const THIRDWEB_API_HOST =
6-
process.env.NEXT_PUBLIC_THIRDWEB_API_HOST || "https://api.thirdweb.com";
7-
86
export type Team = {
97
id: string;
108
name: string;
@@ -35,7 +33,7 @@ export async function getTeamBySlug(slug: string) {
3533
return null;
3634
}
3735

38-
const teamRes = await fetch(`${THIRDWEB_API_HOST}/v1/teams/${slug}`, {
36+
const teamRes = await fetch(`${API_SERVER_URL}/v1/teams/${slug}`, {
3937
headers: {
4038
Authorization: `Bearer ${token}`,
4139
},
@@ -57,7 +55,7 @@ export async function getTeams() {
5755
return [];
5856
}
5957

60-
const teamsRes = await fetch(`${THIRDWEB_API_HOST}/v1/teams`, {
58+
const teamsRes = await fetch(`${API_SERVER_URL}/v1/teams`, {
6159
headers: {
6260
Authorization: `Bearer ${token}`,
6361
},

apps/dashboard/src/@/constants/env.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ export const PROD_OR_DEV_URL = isProd ? "thirdweb.com" : "thirdweb-dev.com";
2020
export const DASHBOARD_STORAGE_URL =
2121
process.env.NEXT_PUBLIC_DASHBOARD_UPLOAD_SERVER ||
2222
"https://storage.thirdweb.com";
23+
24+
export const API_SERVER_URL =
25+
process.env.NEXT_PUBLIC_THIRDWEB_API_HOST || "https://api.thirdweb.com";

apps/dashboard/src/app/(dashboard)/(chain)/utils.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,23 @@ import zytronCTA from "./temp-assets/zytronCTA.jpg";
3737

3838
// END TEMPORARY
3939

40+
import { API_SERVER_URL } from "@/constants/env";
4041
import type { ChainMetadata } from "thirdweb/chains";
4142
import type {
4243
ChainMetadataWithServices,
4344
ChainService,
4445
ChainServices,
4546
} from "./types/chain";
4647

47-
const THIRDWEB_API_HOST =
48-
process.env.NEXT_PUBLIC_THIRDWEB_API_HOST || "https://api.thirdweb.com";
49-
5048
export async function getChains() {
5149
const [chains, chainServices] = await Promise.all([
5250
fetch(
53-
`${THIRDWEB_API_HOST}/v1/chains`,
51+
`${API_SERVER_URL}/v1/chains`,
5452
// revalidate every 60 minutes
5553
{ next: { revalidate: 60 * 60 } },
5654
).then((res) => res.json()) as Promise<{ data: ChainMetadata[] }>,
5755
fetch(
58-
`${THIRDWEB_API_HOST}/v1/chains/services`,
56+
`${API_SERVER_URL}/v1/chains/services`,
5957
// revalidate every 60 minutes
6058
{ next: { revalidate: 60 * 60 } },
6159
).then((res) => res.json()) as Promise<{
@@ -77,12 +75,12 @@ export async function getChain(
7775
): Promise<ChainMetadataWithServices> {
7876
const [chain, chainServices] = await Promise.all([
7977
fetch(
80-
`${THIRDWEB_API_HOST}/v1/chains/${chainIdOrSlug}`,
78+
`${API_SERVER_URL}/v1/chains/${chainIdOrSlug}`,
8179
// revalidate every 15 minutes
8280
{ next: { revalidate: 15 * 60 } },
8381
).then((res) => res.json()) as Promise<{ data: ChainMetadata }>,
8482
fetch(
85-
`${THIRDWEB_API_HOST}/v1/chains/${chainIdOrSlug}/services`,
83+
`${API_SERVER_URL}/v1/chains/${chainIdOrSlug}/services`,
8684
// revalidate every 15 minutes
8785
{ next: { revalidate: 15 * 60 } },
8886
).then((res) => res.json()) as Promise<{ data: ChainServices }>,

apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/utils/fetchEcosystem.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1+
import { API_SERVER_URL } from "@/constants/env";
12
import type { Ecosystem } from "../types";
23

34
export async function fetchEcosystem(slug: string, authToken: string) {
4-
const res = await fetch(
5-
`${process.env.NEXT_PUBLIC_THIRDWEB_API_HOST || "https://api.thirdweb.com"}/v1/ecosystem-wallet/${slug}`,
6-
{
7-
headers: {
8-
Authorization: `Bearer ${authToken}`,
9-
},
5+
const res = await fetch(`${API_SERVER_URL}/v1/ecosystem-wallet/${slug}`, {
6+
headers: {
7+
Authorization: `Bearer ${authToken}`,
108
},
11-
);
9+
});
1210
if (!res.ok) {
1311
const data = await res.json();
1412
console.error(data);

apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/utils/fetchEcosystemList.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1+
import { API_SERVER_URL } from "@/constants/env";
12
import type { Ecosystem } from "../types";
23

34
export async function fetchEcosystemList(authToken: string) {
4-
const res = await fetch(
5-
`${process.env.NEXT_PUBLIC_THIRDWEB_API_HOST || "https://api.thirdweb.com"}/v1/ecosystem-wallet/list`,
6-
{
7-
headers: {
8-
Authorization: `Bearer ${authToken}`,
9-
},
5+
const res = await fetch(`${API_SERVER_URL}/v1/ecosystem-wallet/list`, {
6+
headers: {
7+
Authorization: `Bearer ${authToken}`,
108
},
11-
);
9+
});
1210

1311
if (!res.ok) {
1412
const data = await res.json();

apps/dashboard/src/app/(dashboard)/support/components/create-ticket.action.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import "server-only";
33

44
import { COOKIE_ACTIVE_ACCOUNT, COOKIE_PREFIX_TOKEN } from "@/constants/cookie";
5+
import { API_SERVER_URL } from "@/constants/env";
56
import { cookies } from "next/headers";
67
import { redirect } from "next/navigation";
78

@@ -11,8 +12,6 @@ type State = {
1112
};
1213

1314
const UNTHREAD_API_KEY = process.env.UNTHREAD_API_KEY || "";
14-
const THIRDWEB_API_HOST =
15-
process.env.NEXT_PUBLIC_THIRDWEB_API_HOST || "https://api.thirdweb.com";
1615

1716
const planToCustomerId = {
1817
free: process.env.UNTHREAD_FREE_TIER_ID as string,
@@ -77,7 +76,7 @@ export async function createTicketAction(
7776
// user is not logged in, make them log in
7877
redirect(`/login?next=${encodeURIComponent("/support")}`);
7978
}
80-
const accountRes = await fetch(`${THIRDWEB_API_HOST}/v1/account/me`, {
79+
const accountRes = await fetch(`${API_SERVER_URL}/v1/account/me`, {
8180
method: "GET",
8281
headers: {
8382
Authorization: `Bearer ${token}`,

apps/dashboard/src/app/account/settings/getAccount.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1+
import { API_SERVER_URL } from "@/constants/env";
12
import type { Account } from "@3rdweb-sdk/react/hooks/useApi";
23
import { getAuthToken } from "../../api/lib/getAuthToken";
34

45
export async function getAccount() {
56
const authToken = getAuthToken();
6-
const apiServerURL = new URL(
7-
process.env.NEXT_PUBLIC_THIRDWEB_API_HOST || "https://api.thirdweb.com",
8-
);
7+
const apiServerURL = new URL(API_SERVER_URL);
98

109
apiServerURL.pathname = "/v1/account/me";
1110

apps/dashboard/src/app/api/auth/ensure-login/route.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import { COOKIE_ACTIVE_ACCOUNT, COOKIE_PREFIX_TOKEN } from "@/constants/cookie";
2+
import { API_SERVER_URL } from "@/constants/env";
23
import { cookies } from "next/headers";
34
import { type NextRequest, NextResponse } from "next/server";
45
import { getAddress } from "thirdweb/utils";
56

6-
const THIRDWEB_API_HOST =
7-
process.env.NEXT_PUBLIC_THIRDWEB_API_HOST || "https://api.thirdweb.com";
8-
97
export type EnsureLoginPayload = {
108
pathname: string;
119
address?: string;
@@ -56,7 +54,7 @@ export const GET = async (req: NextRequest) => {
5654
}
5755

5856
// check that the token is valid by checking for the user account
59-
const accountRes = await fetch(`${THIRDWEB_API_HOST}/v1/account/me`, {
57+
const accountRes = await fetch(`${API_SERVER_URL}/v1/account/me`, {
6058
method: "GET",
6159
headers: {
6260
Authorization: `Bearer ${token}`,

0 commit comments

Comments
 (0)