From a494cd4f0ab15cd51bd944186834445322b9684b Mon Sep 17 00:00:00 2001 From: JBB0807 <104856796+JBB0807@users.noreply.github.com> Date: Wed, 7 May 2025 23:30:37 -0700 Subject: [PATCH] now getting the correct IPV6 for proxy --- assignment-service/.env | 1 + assignment-service/.env.development | 2 ++ assignment-service/.env.test | 3 ++- assignment-service/routes/InstructorRouter.js | 4 +++- deployment-service/src/index.js | 12 ++++++++++-- 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/assignment-service/.env b/assignment-service/.env index f5f5b51..19e98cb 100644 --- a/assignment-service/.env +++ b/assignment-service/.env @@ -1,3 +1,4 @@ DB_ASSIGNMENT_SERVICE_URL = "http://db-assignment-service.internal:3000" DEPLOY_API_URL="http://localhost:3006" +PROXY_URL="https://proxy-service.fly.dev" NODE_PORT = 8080 \ No newline at end of file diff --git a/assignment-service/.env.development b/assignment-service/.env.development index b683362..b1d5a57 100644 --- a/assignment-service/.env.development +++ b/assignment-service/.env.development @@ -8,4 +8,6 @@ AWS_REGION='auto' AWS_SECRET_ACCESS_KEY='tsec_6Bz1aMbfYQftuq5WfIVEDZkHwskU4MMjVywdtxSP6uxetEBvkSC2VHI9HfTeDgHr4D6kiz' COMMON_BUCKET='snakeapi-deployment-test-bucket' +PROXY_URL="https://proxy-service.fly.dev" + NODE_PORT=8082 \ No newline at end of file diff --git a/assignment-service/.env.test b/assignment-service/.env.test index 2c83b66..d920c9b 100644 --- a/assignment-service/.env.test +++ b/assignment-service/.env.test @@ -1,4 +1,5 @@ NODE_ENV=docker DB_ASSIGNMENT_SERVICE_URL="http://js-assignment-db-service:3200" DEPLOY_API_URL="http://js-deployment-service:3006/deploy" -NODE_PORT=8082 \ No newline at end of file +NODE_PORT=8082 +PROXY_URL="https://proxy-service.fly.dev" diff --git a/assignment-service/routes/InstructorRouter.js b/assignment-service/routes/InstructorRouter.js index 73b7eb5..8d6fcc1 100644 --- a/assignment-service/routes/InstructorRouter.js +++ b/assignment-service/routes/InstructorRouter.js @@ -8,6 +8,7 @@ const DB_ASSIGNMENT_SERVICE_URL = process.env.DB_ASSIGNMENT_SERVICE_URL || "http://localhost:3000"; const DEPLOY_API_URL = process.env.DEPLOY_API_URL || "http://localhost:3600"; +const PROXY_URL = process.env.PROXY_URL; console.log("DB_ASSIGNMENT_SERVICE_URL:", DB_ASSIGNMENT_SERVICE_URL); console.log("DEPLOY_API_URL:", DEPLOY_API_URL); @@ -63,8 +64,9 @@ intructorRouter.post( // Update the assignment with the deployment details const updatedAssignmentData = { - assignmenturl: ipv6, + assignmenturl: `${PROXY_URL}/${ipv6}`, } + console.log("Updating assignment with deployment details:", updatedAssignmentData); const updateRespone = await axios.put( `${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}`, diff --git a/deployment-service/src/index.js b/deployment-service/src/index.js index 3551744..64ad909 100644 --- a/deployment-service/src/index.js +++ b/deployment-service/src/index.js @@ -163,13 +163,21 @@ app.post("/deploy", async (req, res) => { const ipv6 = v6resp.data.data.allocateIpAddress.ipAddress.address; console.log("Allocated IPv6:", ipv6); + const machines = await fly.get(`/apps/${appName}/machines`); + const firstPrivateIp = machines.data[0]?.private_ip; + if (!firstPrivateIp) { + console.error("No private IP found for the machine:", machines.data); + return machines.status(500).json({ error: "No private IP found" }); + } + console.log("First private IP:", firstPrivateIp); + return res.json({ status: "created", app: appName, ipv4, - ipv6, + ipv6 : firstPrivateIp, url_v4: `http://${ipv4}`, - url_v6: `http://[${ipv6}]`, + url_v6: `http://[${firstPrivateIp}]`, }); } catch (err) { console.error(