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" ];