Skip to content

Commit 86d42c8

Browse files
committed
fix: canary api endpoint
1 parent bf706f8 commit 86d42c8

8 files changed

Lines changed: 51 additions & 59 deletions

File tree

Dockerfile.canary

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ RUN cd astro && npm install && npm cache clean --force
1818
# Copy source code
1919
COPY . .
2020

21-
# Copy frontend env for Vite build
22-
COPY .env.vite.canary .env.canary
21+
# Vite loads `.env.production` when build mode is `production` (same as Dockerfile).
22+
COPY .env.vite.canary .env.production
23+
24+
ENV NODE_ENV=production
2325

2426
# Build the backend (TypeScript compilation)
2527
RUN npm run build:server

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
"build:server": "tsc --project server/tsconfig.json",
1919
"build:astro": "cd astro && npm install && npx astro build",
2020
"build:dev": "npm run generate:developer-docs && vp build --mode development",
21+
"prebuild:canary": "node -e \"require('fs').copyFileSync('.env.vite.canary','.env.production')\"",
22+
"build:canary": "npm run generate:developer-docs && vp build --mode production",
2123
"build-only": "vp build",
2224
"test": "vitest run",
2325
"test:watch": "vitest",

src/hooks/data/DataProvider.tsx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type { Airport, AirportFrequency } from '../../types/airports';
99
import type { Aircraft } from '../../types/aircraft';
1010
import type { Airline } from '../../types/airlines';
1111
import { DataContext } from './useData';
12+
import { clientApiUrl } from '../../utils/clientApiBase';
1213

1314
export function DataProvider({ children }: { children: React.ReactNode }) {
1415
const [airports, setAirports] = useState<Airport[]>([]);
@@ -38,18 +39,10 @@ export function DataProvider({ children }: { children: React.ReactNode }) {
3839
(async () => {
3940
try {
4041
const [runwaysData, sidsData] = await Promise.all([
41-
fetch(
42-
`${
43-
import.meta.env.VITE_SERVER_URL
44-
}/api/data/airports/${icao}/runways`
45-
)
42+
fetch(clientApiUrl(`/api/data/airports/${icao}/runways`))
4643
.then((res) => (res.ok ? res.json() : []))
4744
.catch(() => []),
48-
fetch(
49-
`${
50-
import.meta.env.VITE_SERVER_URL
51-
}/api/data/airports/${icao}/sids`
52-
)
45+
fetch(clientApiUrl(`/api/data/airports/${icao}/sids`))
5346
.then((res) => (res.ok ? res.json() : []))
5447
.catch(() => []),
5548
]);
@@ -133,4 +126,4 @@ export function DataProvider({ children }: { children: React.ReactNode }) {
133126
{children}
134127
</DataContext.Provider>
135128
);
136-
}
129+
}

src/utils/fetch/auth.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import { apiFetch } from '../apiFetch.js';
2+
import { clientApiUrl } from '../clientApiBase.js';
23
import type { User } from '../../types/user';
34

4-
const API_BASE_URL = import.meta.env.VITE_SERVER_URL;
5-
65
export async function getCurrentUser(): Promise<User> {
7-
const API_BASE_URL = import.meta.env.VITE_SERVER_URL;
8-
const res = await apiFetch(`${API_BASE_URL}/api/auth/me`, {
6+
const res = await apiFetch(clientApiUrl('/api/auth/me'), {
97
credentials: 'include',
108
});
119
if (!res.ok) throw new Error('Failed to fetch user');
@@ -16,7 +14,7 @@ export async function updateTutorialStatus(
1614
completed: boolean
1715
): Promise<boolean> {
1816
try {
19-
const response = await apiFetch(`${API_BASE_URL}/api/auth/tutorial`, {
17+
const response = await apiFetch(clientApiUrl('/api/auth/tutorial'), {
2018
method: 'PUT',
2119
credentials: 'include',
2220
headers: {
@@ -33,7 +31,7 @@ export async function updateTutorialStatus(
3331

3432
export async function logout(): Promise<boolean> {
3533
try {
36-
const response = await apiFetch(`${API_BASE_URL}/api/auth/logout`, {
34+
const response = await apiFetch(clientApiUrl('/api/auth/logout'), {
3735
method: 'POST',
3836
credentials: 'include',
3937
});
@@ -45,9 +43,9 @@ export async function logout(): Promise<boolean> {
4543
}
4644

4745
export function getDiscordLoginUrl(callback?: string): string {
48-
const url = new URL(`${API_BASE_URL}/api/auth/discord`);
46+
const url = new URL(clientApiUrl('/api/auth/discord'));
4947
if (callback) {
5048
url.searchParams.set('callback', callback);
5149
}
5250
return url.toString();
53-
}
51+
}

src/utils/fetch/data.ts

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import type { TesterSettings } from './testers';
55
import type { Notification as AdminNotification } from '../fetch/admin';
66
import { clientApiUrl } from '../clientApiBase';
77

8+
function dataApiUrl(endpoint: string): string {
9+
return clientApiUrl(`/api/data/${endpoint}`);
10+
}
11+
812
interface AvailableImage {
913
filename: string;
1014
path: string;
@@ -13,9 +17,7 @@ interface AvailableImage {
1317

1418
async function fetchData<T>(endpoint: string): Promise<T[]> {
1519
try {
16-
const response = await fetch(
17-
`${import.meta.env.VITE_SERVER_URL}/api/data/${endpoint}`
18-
);
20+
const response = await fetch(dataApiUrl(endpoint));
1921
if (!response.ok) {
2022
throw new Error(`HTTP error! status: ${response.status}`);
2123
}
@@ -73,18 +75,14 @@ export async function fetchLeaderboard(): Promise<
7375
}>
7476
>
7577
> {
76-
const response = await fetch(
77-
`${import.meta.env.VITE_SERVER_URL}/api/data/leaderboard`
78-
);
78+
const response = await fetch(clientApiUrl('/api/data/leaderboard'));
7979
if (!response.ok) throw new Error('Failed to fetch leaderboard');
8080
return response.json();
8181
}
8282

8383
export async function getTesterSettings(): Promise<TesterSettings> {
8484
try {
85-
const response = await fetch(
86-
`${import.meta.env.VITE_SERVER_URL}/api/data/settings`
87-
);
85+
const response = await fetch(clientApiUrl('/api/data/settings'));
8886
if (!response.ok) {
8987
throw new Error(`HTTP error! status: ${response.status}`);
9088
}
@@ -97,9 +95,7 @@ export async function getTesterSettings(): Promise<TesterSettings> {
9795
}
9896

9997
export async function fetchActiveNotifications(): Promise<AdminNotification[]> {
100-
const response = await fetch(
101-
clientApiUrl('/api/data/notifications/active')
102-
);
98+
const response = await fetch(clientApiUrl('/api/data/notifications/active'));
10399
if (!response.ok) {
104100
throw new Error(`HTTP error! status: ${response.status}`);
105101
}
@@ -109,16 +105,18 @@ export async function fetchActiveNotifications(): Promise<AdminNotification[]> {
109105
export async function fetchUserRanks(
110106
userId: string
111107
): Promise<Record<string, number | null>> {
112-
const response = await fetch(
113-
`${import.meta.env.VITE_SERVER_URL}/api/data/ranks/${userId}`
114-
);
108+
const response = await fetch(clientApiUrl(`/api/data/ranks/${userId}`));
115109
if (!response.ok) {
116110
throw new Error('Failed to fetch user ranks');
117111
}
118112
return response.json();
119113
}
120114

121-
export async function fetchRoute(from: string, to: string, runway?: string): Promise<{
115+
export async function fetchRoute(
116+
from: string,
117+
to: string,
118+
runway?: string
119+
): Promise<{
122120
path: Array<{ name: string; x: number; y: number; type: string }>;
123121
distance: number;
124122
route: string;
@@ -130,9 +128,7 @@ export async function fetchRoute(from: string, to: string, runway?: string): Pro
130128
try {
131129
const params = new URLSearchParams({ from, to });
132130
if (runway) params.set('runway', runway);
133-
const response = await fetch(
134-
`${import.meta.env.VITE_SERVER_URL}/api/data/findRoute?${params}`
135-
);
131+
const response = await fetch(clientApiUrl(`/api/data/findRoute?${params}`));
136132
if (!response.ok) {
137133
throw new Error(`HTTP error! status: ${response.status}`);
138134
}

src/utils/fetch/metar.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { apiFetch } from '../apiFetch.js';
2+
import { clientApiUrl } from '../clientApiBase.js';
23
import type { MetarData } from '../../types/metar';
34

4-
const API_BASE_URL = import.meta.env.VITE_SERVER_URL;
5-
65
export async function fetchMetar(icao: string): Promise<MetarData | null> {
76
try {
8-
const response = await apiFetch(`${API_BASE_URL}/api/metar/${icao}`, {
7+
const response = await apiFetch(clientApiUrl(`/api/metar/${icao}`), {
98
credentials: 'include',
109
});
1110

@@ -27,4 +26,4 @@ export async function fetchMetar(icao: string): Promise<MetarData | null> {
2726
console.error('Error fetching METAR:', error);
2827
return null;
2928
}
30-
}
29+
}

src/utils/fetch/settings.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { apiFetch } from '../apiFetch.js';
2+
import { clientApiUrl } from '../clientApiBase.js';
23
import type { Settings } from '../../types/settings';
34

4-
const API_BASE_URL = import.meta.env.VITE_SERVER_URL;
5-
65
export async function fetchUserSettings(): Promise<Settings> {
7-
const res = await apiFetch(`${API_BASE_URL}/api/auth/me`, {
6+
const res = await apiFetch(clientApiUrl('/api/auth/me'), {
87
credentials: 'include',
98
});
109
if (!res.ok) throw new Error('Failed to fetch settings');
@@ -15,11 +14,11 @@ export async function fetchUserSettings(): Promise<Settings> {
1514
export async function updateUserSettings(
1615
settings: Partial<Settings>
1716
): Promise<void> {
18-
const res = await apiFetch(`${API_BASE_URL}/api/auth/me`, {
17+
const res = await apiFetch(clientApiUrl('/api/auth/me'), {
1918
method: 'PUT',
2019
credentials: 'include',
2120
headers: { 'Content-Type': 'application/json' },
2221
body: JSON.stringify({ settings }),
2322
});
2423
if (!res.ok) throw new Error('Failed to update settings');
25-
}
24+
}

src/utils/fetch/testers.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { apiFetch } from '../apiFetch.js';
2-
const API_BASE_URL = import.meta.env.VITE_SERVER_URL || '';
2+
import { clientApiUrl } from '../clientApiBase.js';
33

44
export interface Tester {
55
id: number;
@@ -28,14 +28,17 @@ export interface TesterSettings {
2828
}
2929

3030
async function makeTesterRequest(endpoint: string, options?: RequestInit) {
31-
const response = await apiFetch(`${API_BASE_URL}/api/admin/testers${endpoint}`, {
32-
credentials: 'include',
33-
headers: {
34-
'Content-Type': 'application/json',
35-
...options?.headers,
36-
},
37-
...options,
38-
});
31+
const response = await apiFetch(
32+
clientApiUrl(`/api/admin/testers${endpoint}`),
33+
{
34+
credentials: 'include',
35+
headers: {
36+
'Content-Type': 'application/json',
37+
...options?.headers,
38+
},
39+
...options,
40+
}
41+
);
3942

4043
if (!response.ok) {
4144
if (response.status === 403) {
@@ -89,4 +92,4 @@ export async function updateTesterSettings(
8992
method: 'PUT',
9093
body: JSON.stringify(settings),
9194
});
92-
}
95+
}

0 commit comments

Comments
 (0)