From 4dfae6ad86a09f3a632e944d9790e058a3ce9baf Mon Sep 17 00:00:00 2001 From: Pietro Bonaldo Date: Wed, 8 Oct 2025 20:35:11 +0200 Subject: [PATCH 1/4] Add ENABLE_EXTERNAL_APIS env var, allowing opt-out of external apis --- Dockerfile | 1 + client/api.ts | 3 ++- client/pages/New.tsx | 14 ++++++++++---- server/environment.py | 1 + server/main.py | 7 ++++++- server/routers/flights.py | 3 +++ 6 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 90bdca5..988a57c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,6 +31,7 @@ ENV APP_PATH=/app ENV DATA_PATH=/data ENV JETLOG_PORT=3000 ENV TOKEN_DURATION=7 +ENV ENABLE_EXTERNAL_APIS=true ENV USE_IPV6=false RUN mkdir -p ${APP_PATH} diff --git a/client/api.ts b/client/api.ts index e3a8612..460556d 100644 --- a/client/api.ts +++ b/client/api.ts @@ -2,9 +2,10 @@ import axios, {Axios} from 'axios'; import TokenStorage from './storage/tokenStorage'; const config = await fetch('./config').then((response) => response.json()) - .catch(() => ({ BASE_URL: '/' })); + .catch(() => ({ BASE_URL: '/', ENABLE_EXTERNAL_APIS: true })); export const BASE_URL = config.BASE_URL == '/' ? '' : config.BASE_URL; +export const ENABLE_EXTERNAL_APIS = config.ENABLE_EXTERNAL_APIS; // TODO improve this because there's a lot of repetition (get, post, delete are pretty much exactly the same) // perhaps one method for each endpoint? i.e. API.getFlights(), ... diff --git a/client/pages/New.tsx b/client/pages/New.tsx index fc2665c..69c5e3c 100644 --- a/client/pages/New.tsx +++ b/client/pages/New.tsx @@ -3,7 +3,7 @@ import { useNavigate } from 'react-router-dom'; import { Heading, Label, Button, Input, Select, TextArea } from '../components/Elements'; import SearchInput from '../components/SearchInput' -import API from '../api'; +import API, { ENABLE_EXTERNAL_APIS } from '../api'; import { objectFromForm } from '../utils'; import { Airline, Airport, User } from '../models'; import ConfigStorage from '../storage/configStorage'; @@ -151,6 +151,10 @@ export default function New() { }; const attemptFetchFlight = async () => { + if (!ENABLE_EXTERNAL_APIS) { + return; + } + API.getRemote(`https://api.adsbdb.com/v0/callsign/${flightNumber}`) .then(async (data: Object) => { const originICAO = data["response"]["flightroute"]["origin"]["icao_code"]; @@ -246,9 +250,11 @@ export default function New() { onChange={(e) => setFlightNumber(e.target.value)} /> -
-
+ { ENABLE_EXTERNAL_APIS && +
+
+ }
-
-
+ { ENABLE_EXTERNAL_APIS && +
+
+ }