From fec0e09cb0e8091893986ce3994a3e5b3dc3fc69 Mon Sep 17 00:00:00 2001 From: Trey Hayden Date: Mon, 14 Aug 2023 13:33:44 -0400 Subject: [PATCH] fixing protocol issue for player forwarding --- cts/.env.example | 4 +++ cts/docker-compose.yml | 4 ++- player/service/plugins/routes/v1/courses.js | 33 +++++++++++---------- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/cts/.env.example b/cts/.env.example index 22c9d57..dcf89b5 100644 --- a/cts/.env.example +++ b/cts/.env.example @@ -1,6 +1,7 @@ HOSTNAME=localhost PLAYER_ROOT_PATH=/player +PLAYER_BASE_URL=http://player:3398/player PLAYER_CONTENT_URL=http://localhost:3398/player/content PLAYER_KEY=cts PLAYER_SECRET=player-secret @@ -9,3 +10,6 @@ PLAYER_TOKEN_SECRET=player-token-secret LRS_ENDPOINT=http://host.docker.internal:8081/20.1.x/lrs/default/ LRS_USERNAME=dev-tools-xapi LRS_PASSWORD=dev-tools-xapi-password + +## Dev Only, set to 0 to allow self-signed certs +NODE_TLS_REJECT_UNAUTHORIZED=1 diff --git a/cts/docker-compose.yml b/cts/docker-compose.yml index ac1b4f4..8746619 100644 --- a/cts/docker-compose.yml +++ b/cts/docker-compose.yml @@ -63,9 +63,10 @@ services: - DATABASE_USER=catapult - DATABASE_USER_PASSWORD=quartz - DATABASE_NAME=catapult_cts - - PLAYER_BASE_URL=http://player:3398${PLAYER_ROOT_PATH} + - PLAYER_BASE_URL - PLAYER_KEY - PLAYER_SECRET + - NODE_TLS_REJECT_UNAUTHORIZED networks: - public @@ -103,6 +104,7 @@ services: rdbms: image: mysql:8.0.17 + restart: always volumes: - catapult-cts-data:/var/lib/mysql - ./init_db.sh:/docker-entrypoint-initdb.d/init_db.sh:ro diff --git a/player/service/plugins/routes/v1/courses.js b/player/service/plugins/routes/v1/courses.js index 52fca4b..88a2ab2 100644 --- a/player/service/plugins/routes/v1/courses.js +++ b/player/service/plugins/routes/v1/courses.js @@ -714,10 +714,12 @@ module.exports = { } //Debug messages for troubleshooting host and path issuse - MB - console.log("req.url.protocol is ", req.url.protocol); - console.log("req.url.host is ", req.url.host); - console.log("rootPath is ", rootPath); + console.log("req.url.protocol is ", req.url.protocol); + // console.log("req.url.host is ", req.url.host); + // console.log("rootPath is ", rootPath); + let forwardingHeader = req.headers["x-forwarded-proto"]; + let protocol = (forwardingHeader === "https") ? "https:" : req.url.protocol; const lmsActivityId = courseAu.lms_id, publisherActivityId = course.metadata.aus[auIndex].id, @@ -728,7 +730,7 @@ module.exports = { moveOn = req.payload.moveOn || courseAu.metadata.moveOn || "NotApplicable", alternateEntitlementKey = req.payload.alternateEntitlementKey || courseAu.metadata.alternateEntitlementKey, - baseUrl = `${req.url.protocol}//${req.url.host}${rootPath}`, + baseUrl = `${protocol}//${req.url.host}${rootPath}`, endpoint = `${baseUrl}/lrs`, sessionId = uuidv4(), contextTemplate = { @@ -744,9 +746,10 @@ module.exports = { } }; - //Debug messages for troubleshooting host and path issuse - MB - console.log("Base url is ", baseUrl); - console.log("Which makes endpoint ", endpoint); + // //Debug messages for troubleshooting host and path issuse - MB + // console.log("Base url is ", baseUrl); + // console.log("Which makes endpoint ", endpoint); + // console.log("Forwarded Header: ", req.headers["x-forwarded-proto"]); if (req.payload.contextTemplateAdditions) { Hoek.merge(contextTemplate, req.payload.contextTemplateAdditions, { nullOverride: false }); @@ -781,10 +784,10 @@ module.exports = { contextTemplate }; - //Debug messages for troubleshooting host and path issuse - MB - console.log("lmsLaunchDataStateParams.toString() is ", lmsLaunchDataStateParams.toString()); - console.log("lmsLaunchDataStateParams is ", lmsLaunchDataStateParams); - console.log("lmsLaunchDataPayload is ", lmsLaunchDataPayload); + // //Debug messages for troubleshooting host and path issuse - MB + // console.log("lmsLaunchDataStateParams.toString() is ", lmsLaunchDataStateParams.toString()); + // console.log("lmsLaunchDataStateParams is ", lmsLaunchDataStateParams); + // console.log("lmsLaunchDataPayload is ", lmsLaunchDataPayload); if (courseAu.metadata.entitlementKey) { lmsLaunchDataPayload.entitlementKey = { @@ -811,10 +814,10 @@ module.exports = { payload: lmsLaunchDataPayload } ); - //Debug messages for troubleshooting host and path issuse - MB - console.log("lmsLaunchDataPayload is ", lmsLaunchDataPayload); - console.log("activities/state?${lmsLaunchDataStateParams.toString()} is ", `activities/state?${lmsLaunchDataStateParams.toString()}`); - console.log("lmsLaunchDataResponse is ", lmsLaunchDataResponse); + // //Debug messages for troubleshooting host and path issuse - MB + // console.log("lmsLaunchDataPayload is ", lmsLaunchDataPayload); + // console.log("activities/state?${lmsLaunchDataStateParams.toString()} is ", `activities/state?${lmsLaunchDataStateParams.toString()}`); + // console.log("lmsLaunchDataResponse is ", lmsLaunchDataResponse); lmsLaunchDataResponseBody = await Wreck.read(lmsLaunchDataResponse, { json: true });