From e3d80b3a0395902b5aa222c3570e5697295d2b20 Mon Sep 17 00:00:00 2001 From: Jamie King Date: Tue, 19 Nov 2024 16:00:15 +0000 Subject: [PATCH] Segregated development URLs --- Dockerfile | 1 + client/Root.jsx | 4 ++-- client/Show.jsx | 6 +++--- server.js | 1 - 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index f42187e..05ee274 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,6 +13,7 @@ RUN npm run build # setup app FROM node:20 WORKDIR /app +ENV NODE_ENV="production" # install production dependencies COPY package*.json . diff --git a/client/Root.jsx b/client/Root.jsx index 3d7c42d..712b53b 100644 --- a/client/Root.jsx +++ b/client/Root.jsx @@ -25,13 +25,13 @@ export default function Root() { setLoading(true) - const url = "http://localhost:3000/locations" + const url = (process.env.NODE_ENV === "development") ? "http://localhost:3000/locations" : "/locations" if (searchTimeout) clearTimeout(searchTimeout); searchTimeout = setTimeout(async () => { try { - const response = await fetch("http://localhost:3000/locations", { + const response = await fetch(url, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ string: search }), diff --git a/client/Show.jsx b/client/Show.jsx index ee2e4e4..2dbe66f 100644 --- a/client/Show.jsx +++ b/client/Show.jsx @@ -44,9 +44,9 @@ export default function Weather() { const fetchWeatherData = async () => { // urls - const weatherUrl = "http://localhost:3000/weather"; - const forecastUrl = "http://localhost:3000/forecast"; - const airQualityUrl = "http://localhost:3000/airquality"; + const weatherUrl =(process.env.NODE_ENV === "development") ? "http://localhost:3000/weather" : "/weather"; + const forecastUrl = (process.env.NODE_ENV === "development") ? "http://localhost:3000/forecast" : "/forecast"; + const airQualityUrl = (process.env.NODE_ENV === "development") ? "http://localhost:3000/airquality" : "/airquality"; const lat = searchParams.get("lat"); const lon = searchParams.get("lon"); const tz = tz_lookup(lat, lon) diff --git a/server.js b/server.js index 9a34702..e8e2131 100644 --- a/server.js +++ b/server.js @@ -32,7 +32,6 @@ app.use(express.urlencoded({ extended: false })); app.use((req, res, next) => { const allowedOrigins = [ - "http://localhost:3000", "http://127.0.0.1:8080", "http://127.0.0.1:3000" ];