Skip to content

Commit 9cc6617

Browse files
committed
Remove /api prefix from API routes and update configs
API endpoints in the Express server no longer use the /api prefix. Updated all frontend fetch calls to match the new routes. Adjusted docker-compose.prod.yml to use path-based routing and strip prefixes for both API and WebSocket services, ensuring compatibility with Traefik routing and new public URLs.
1 parent 3bf50c9 commit 9cc6617

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

apps/api/src/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const app = express();
88
app.use(cors());
99
app.use(express.json());
1010

11-
app.get("/api/static/versions", async (_req, res) => {
11+
app.get("/static/versions", async (_req, res) => {
1212
try {
1313
const airportsVersion = await rdsGetSingle("static_airports:version");
1414
const firsVersion = await rdsGetSingle("static_firs:version");
@@ -27,7 +27,7 @@ app.get("/api/static/versions", async (_req, res) => {
2727
}
2828
});
2929

30-
app.get("/api/static/:type", async (req, res) => {
30+
app.get("/static/:type", async (req, res) => {
3131
try {
3232
const { type } = req.params;
3333
const allowedTypes = ["airports", "tracons", "firs", "airlines"];
@@ -44,7 +44,7 @@ app.get("/api/static/:type", async (req, res) => {
4444
}
4545
});
4646

47-
app.get("/api/data/init", async (_req, res) => {
47+
app.get("/data/init", async (_req, res) => {
4848
try {
4949
const all = await rdsGetSingle("ws:all");
5050
if (!all) return res.status(404).json({ error: "Initial data not found" });
@@ -56,7 +56,7 @@ app.get("/api/data/init", async (_req, res) => {
5656
}
5757
});
5858

59-
app.get("/api/data/pilot/:callsign", async (req, res) => {
59+
app.get("/data/pilot/:callsign", async (req, res) => {
6060
try {
6161
const { callsign } = req.params;
6262
console.log("Requested pilot:", callsign);
@@ -71,7 +71,7 @@ app.get("/api/data/pilot/:callsign", async (req, res) => {
7171
}
7272
});
7373

74-
app.get("/api/data/airport/:icao", async (req, res) => {
74+
app.get("/data/airport/:icao", async (req, res) => {
7575
try {
7676
const { icao } = req.params;
7777
console.log("Requested airport:", icao);
@@ -86,7 +86,7 @@ app.get("/api/data/airport/:icao", async (req, res) => {
8686
}
8787
});
8888

89-
app.get("/api/data/controller/:callsign", async (req, res) => {
89+
app.get("/data/controller/:callsign", async (req, res) => {
9090
try {
9191
const { callsign } = req.params;
9292
console.log("Requested controller:", callsign);
@@ -101,7 +101,7 @@ app.get("/api/data/controller/:callsign", async (req, res) => {
101101
}
102102
});
103103

104-
app.get("/api/data/track/:id", async (req, res) => {
104+
app.get("/data/track/:id", async (req, res) => {
105105
try {
106106
const { id } = req.params;
107107
console.log("Requested track:", id);

apps/web/storage/cache.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export async function initData(setStatus?: StatusSetter): Promise<void> {
2626
await dxInitDatabases();
2727
setStatus?.((prev) => ({ ...prev, indexedDB: true }));
2828

29-
const data = (await fetch(`${BASE_URL}/api/data/init`).then((res) => res.json())) as WsAll;
29+
const data = (await fetch(`${BASE_URL}/data/init`).then((res) => res.json())) as WsAll;
3030
setStatus?.((prev) => ({ ...prev, initData: true }));
3131

3232
await initAirportFeatures();
@@ -117,5 +117,5 @@ export async function getCachedFir(id: string): Promise<FIRFeature | null> {
117117
}
118118

119119
export async function fetchTrackPoints(id: string): Promise<TrackPoint[]> {
120-
return await fetch(`${BASE_URL}/api/data/track/${id}`).then((res) => res.json());
120+
return await fetch(`${BASE_URL}/data/track/${id}`).then((res) => res.json());
121121
}

apps/web/storage/dexie.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ db.version(1).stores({
3030
const BASE_URL = process.env.NEXT_PUBLIC_API_URL || "http://localhost:3001";
3131

3232
export async function dxInitDatabases(): Promise<void> {
33-
const serverVersions = (await fetch(`${BASE_URL}/api/static/versions`).then((res) => res.json())) as StaticVersions;
33+
const serverVersions = (await fetch(`${BASE_URL}/static/versions`).then((res) => res.json())) as StaticVersions;
3434
const localVersions: StaticVersions = JSON.parse(localStorage.getItem("databaseVersions") || "{}");
3535

3636
if (serverVersions.airportsVersion !== localVersions.airportsVersion) {
@@ -67,7 +67,7 @@ export async function dxInitDatabases(): Promise<void> {
6767
}
6868

6969
async function fetchStaticData(type: string): Promise<any> {
70-
const response = await fetch(`${BASE_URL}/api/static/${type}`);
70+
const response = await fetch(`${BASE_URL}/static/${type}`);
7171
const data = await response.json();
7272

7373
return data;

docker/docker-compose.prod.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ services:
2727
context: ..
2828
dockerfile: apps/web/Dockerfile
2929
args:
30-
NEXT_PUBLIC_API_URL: "https://api.radar.skruellex.com"
31-
NEXT_PUBLIC_WEBSOCKET_URL: "wss://ws.radar.skruellex.com"
30+
NEXT_PUBLIC_API_URL: "https://api.radar.skruellex.com/api"
31+
NEXT_PUBLIC_WEBSOCKET_URL: "wss://ws.radar.skruellex.com/ws"
3232
container_name: sr24_web
3333
restart: always
3434
environment:
@@ -69,11 +69,13 @@ services:
6969
- sr24_backend
7070
labels:
7171
- "traefik.enable=true"
72-
- "traefik.http.routers.api.rule=Host(`api.radar.skruellex.com`)"
72+
- "traefik.http.routers.api.rule=Host(`radar.skruellex.com`) && PathPrefix(`/api`)"
7373
- "traefik.http.routers.api.entrypoints=websecure"
7474
- "traefik.http.routers.api.tls=true"
7575
- "traefik.http.routers.api.tls.certresolver=letsencrypt"
7676
- "traefik.http.services.api.loadbalancer.server.port=3001"
77+
- "traefik.http.middlewares.api-stripprefix.stripprefix.prefixes=/api"
78+
- "traefik.http.routers.api.middlewares=api-stripprefix"
7779
- "traefik.docker.network=traefik_proxy"
7880

7981
ws:
@@ -96,11 +98,13 @@ services:
9698
- sr24_backend
9799
labels:
98100
- "traefik.enable=true"
99-
- "traefik.http.routers.ws.rule=Host(`ws.radar.skruellex.com`)"
101+
- "traefik.http.routers.ws.rule=Host(`radar.skruellex.com`) && PathPrefix(`/ws`)"
100102
- "traefik.http.routers.ws.entrypoints=websecure"
101103
- "traefik.http.routers.ws.tls=true"
102104
- "traefik.http.routers.ws.tls.certresolver=letsencrypt"
103105
- "traefik.http.services.ws.loadbalancer.server.port=3002"
106+
- "traefik.http.middlewares.ws-stripprefix.stripprefix.prefixes=/ws"
107+
- "traefik.http.routers.ws.middlewares=ws-stripprefix"
104108
- "traefik.docker.network=traefik_proxy"
105109

106110
ingestion:

0 commit comments

Comments
 (0)