From 18bbefb35e34adf88e64aff8beb5d0e663fa9c72 Mon Sep 17 00:00:00 2001 From: angelalvaigle Date: Sat, 7 Dec 2024 14:35:15 +0100 Subject: [PATCH] env vbles config --- .github/workflows/release.yml | 12 ++++++- docker-compose.yml | 9 ++--- gatewayservice/gateway-service.js | 3 +- questionservice/question-service.js | 2 +- questionservice/question-service.test.js | 2 +- statservice/package-lock.json | 46 ------------------------ statservice/package.json | 2 -- statservice/stat-service.js | 11 +----- statservice/stat-service.test.js | 2 +- users/authservice/auth-service.js | 2 +- users/authservice/auth-service.test.js | 2 +- users/userservice/package-lock.json | 37 ------------------- users/userservice/package.json | 4 +-- users/userservice/user-service.js | 11 +----- users/userservice/user-service.test.js | 2 +- webapp/e2e/test-environment-setup.js | 8 +++-- 16 files changed, 32 insertions(+), 123 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 70f1458..0882305 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -189,6 +189,12 @@ jobs: ] steps: - name: Deploy over SSH + env: + ORIGIN_URL: ${{ env.ORIGIN_URL }} + AUTH_SERVICE_URL: ${{ env.AUTH_SERVICE_URL }} + USER_SERVICE_URL: ${{ env.USER_SERVICE_URL }} + QUESTION_SERVICE_URL: ${{ env.QUESTION_SERVICE_URL }} + STAT_SERVICE_URL: ${{ env.STAT_SERVICE_URL }} uses: fifsky/ssh-action@master with: host: ${{ secrets.DEPLOY_HOST }} @@ -196,6 +202,10 @@ jobs: key: ${{ secrets.DEPLOY_KEY }} command: | wget https://raw.githubusercontent.com/arquisoft/wiq_7/master/docker-compose.yml -O docker-compose.yml - wget https://raw.githubusercontent.com/arquisoft/wiq_7/master/.env -O .env + echo "ORIGIN_URL=${{ env.ORIGIN_URL }}" >> .env + echo "AUTH_SERVICE_URL=${{ env.AUTH_SERVICE_URL }}" >> .env + echo "USER_SERVICE_URL=${{ env.USER_SERVICE_URL }}" >> .env + echo "QUESTION_SERVICE_URL=${{ env.QUESTION_SERVICE_URL }}" >> .env + echo "STAT_SERVICE_URL=${{ env.STAT_SERVICE_URL }}" >> .env docker compose --profile prod down docker compose --profile prod up -d --pull always diff --git a/docker-compose.yml b/docker-compose.yml index c0279cc..8df1930 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -25,7 +25,7 @@ services: networks: - mynetwork environment: - MONGODB_URI: mongodb://mongodb:27017/userdb + MONGODB_USER: mongodb://mongodb:27017/userdb userservice: container_name: userservice-${teamname:-defaultASW} @@ -39,7 +39,7 @@ services: networks: - mynetwork environment: - MONGODB_URI: mongodb://mongodb:27017/userdb + MONGODB_USER: mongodb://mongodb:27017/userdb questionservice: container_name: questionservice-${teamname:-defaultASW} @@ -57,7 +57,7 @@ services: networks: - mynetwork environment: - MONGODB_URI: mongodb://mongodb:27017/questiondb + MONGODB_QUESTION: mongodb://mongodb:27017/questiondb statservice: container_name: statservice-${teamname:-defaultASW} @@ -75,7 +75,7 @@ services: networks: - mynetwork environment: - MONGODB_URI: mongodb://mongodb:27017/statdb + MONGODB_STAT: mongodb://mongodb:27017/statdb gatewayservice: container_name: gatewayservice-${teamname:-defaultASW} @@ -97,6 +97,7 @@ services: networks: - mynetwork environment: + ORIGIN_URL: http://localhost:3000 AUTH_SERVICE_URL: http://authservice:8002 USER_SERVICE_URL: http://userservice:8001 QUESTION_SERVICE_URL: http://questionservice:8003 diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js index 1231443..363284e 100644 --- a/gatewayservice/gateway-service.js +++ b/gatewayservice/gateway-service.js @@ -15,6 +15,7 @@ if (process.env.NODE_ENV === 'development') { const app = express(); const port = 8000; +const originUrl = process.env.ORIGIN_URL || 'http://localhost:3000'; const authServiceUrl = process.env.AUTH_SERVICE_URL || 'http://localhost:8002'; const userServiceUrl = process.env.USER_SERVICE_URL || 'http://localhost:8001'; const questionServiceUrl = @@ -23,7 +24,7 @@ const statServiceUrl = process.env.STAT_SERVICE_URL || 'http://localhost:8004'; app.use( cors({ - origin: 'http://localhost:3000', + origin: originUrl, credentials: true, allowedHeaders: ['Authorization', 'Content-Type'], }) diff --git a/questionservice/question-service.js b/questionservice/question-service.js index 65be4a0..c96e1fe 100644 --- a/questionservice/question-service.js +++ b/questionservice/question-service.js @@ -11,7 +11,7 @@ app.use(express.json()); // Connect to MongoDB const mongoUri = - process.env.MONGODB_URI || 'mongodb://localhost:27017/questiondb'; + process.env.MONGODB_QUESTION || 'mongodb://localhost:27017/questiondb'; mongoose.connect(mongoUri); app.use('/', questionRouter); diff --git a/questionservice/question-service.test.js b/questionservice/question-service.test.js index d07ef33..da05226 100644 --- a/questionservice/question-service.test.js +++ b/questionservice/question-service.test.js @@ -16,7 +16,7 @@ let app; beforeAll(async () => { mongoServer = await MongoMemoryServer.create(); const mongoUri = mongoServer.getUri(); - process.env.MONGODB_URI = mongoUri; + process.env.MONGODB_QUESTION = mongoUri; app = (await import('./question-service.js')).default; // Import app dynamically to ensure MONGODB_URI is set }); diff --git a/statservice/package-lock.json b/statservice/package-lock.json index b35ec73..fbe11ba 100644 --- a/statservice/package-lock.json +++ b/statservice/package-lock.json @@ -9,8 +9,6 @@ "version": "1.0.0", "license": "ISC", "dependencies": { - "cookie-parser": "^1.4.7", - "cors": "^2.8.5", "express": "^4.18.2", "http-status-codes": "^2.2.0", "jsonwebtoken": "^9.0.2", @@ -1768,28 +1766,6 @@ "node": ">= 0.6" } }, - "node_modules/cookie-parser": { - "version": "1.4.7", - "resolved": "https://registry.npmjs.org/cookie-parser/-/cookie-parser-1.4.7.tgz", - "integrity": "sha512-nGUvgXnotP3BsjiLX2ypbQnWoGUPIIfHQNZkkC668ntrzGWEZVW70HDEB1qnNGMicPje6EttlIgzo51YSwNQGw==", - "license": "MIT", - "dependencies": { - "cookie": "0.7.2", - "cookie-signature": "1.0.6" - }, - "engines": { - "node": ">= 0.8.0" - } - }, - "node_modules/cookie-parser/node_modules/cookie": { - "version": "0.7.2", - "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz", - "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, "node_modules/cookie-signature": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", @@ -1803,19 +1779,6 @@ "dev": true, "license": "MIT" }, - "node_modules/cors": { - "version": "2.8.5", - "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", - "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", - "license": "MIT", - "dependencies": { - "object-assign": "^4", - "vary": "^1" - }, - "engines": { - "node": ">= 0.10" - } - }, "node_modules/create-jest": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/create-jest/-/create-jest-29.7.0.tgz", @@ -4308,15 +4271,6 @@ "node": ">=8" } }, - "node_modules/object-assign": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", - "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", - "license": "MIT", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/object-inspect": { "version": "1.13.3", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.3.tgz", diff --git a/statservice/package.json b/statservice/package.json index 272e5da..97509a6 100644 --- a/statservice/package.json +++ b/statservice/package.json @@ -22,8 +22,6 @@ }, "homepage": "https://github.com/Arquisoft/wiq_7#readme", "dependencies": { - "cookie-parser": "^1.4.7", - "cors": "^2.8.5", "express": "^4.18.2", "http-status-codes": "^2.2.0", "jsonwebtoken": "^9.0.2", diff --git a/statservice/stat-service.js b/statservice/stat-service.js index 17a46db..f588b4a 100644 --- a/statservice/stat-service.js +++ b/statservice/stat-service.js @@ -1,24 +1,15 @@ // question-service.js import express from 'express'; import mongoose from 'mongoose'; -import cors from 'cors'; -import cookieParser from 'cookie-parser'; import statRouter from './stat-router.js'; const app = express(); const port = 8004; -app.use( - cors({ - origin: 'http://localhost:8000', // Dirección del gateway. - credentials: true, // Permite enviar cookies. - }) -); app.use(express.json()); -app.use(cookieParser()); // Connect to MongoDB -const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/statdb'; +const mongoUri = process.env.MONGODB_STAT || 'mongodb://localhost:27017/statdb'; mongoose.connect(mongoUri); app.use('/', statRouter); diff --git a/statservice/stat-service.test.js b/statservice/stat-service.test.js index f8f8f58..28725ad 100644 --- a/statservice/stat-service.test.js +++ b/statservice/stat-service.test.js @@ -16,7 +16,7 @@ let app; beforeAll(async () => { mongoServer = await MongoMemoryServer.create(); const mongoUri = mongoServer.getUri(); - process.env.MONGODB_URI = mongoUri; + process.env.MONGODB_STAT = mongoUri; app = (await import('./stat-service.js')).default; // Import app dynamically to ensure MONGODB_URI is set }); diff --git a/users/authservice/auth-service.js b/users/authservice/auth-service.js index 6f254a6..fd2bb03 100644 --- a/users/authservice/auth-service.js +++ b/users/authservice/auth-service.js @@ -9,7 +9,7 @@ const port = 8002; app.use(express.json()); // Connect to MongoDB -const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/userdb'; +const mongoUri = process.env.MONGODB_USER || 'mongodb://localhost:27017/userdb'; console.log('auth service'); console.log(mongoUri); diff --git a/users/authservice/auth-service.test.js b/users/authservice/auth-service.test.js index 946333e..f428d9d 100644 --- a/users/authservice/auth-service.test.js +++ b/users/authservice/auth-service.test.js @@ -24,7 +24,7 @@ async function addUser(user) { beforeAll(async () => { mongoServer = await MongoMemoryServer.create(); const mongoUri = mongoServer.getUri(); - process.env.MONGODB_URI = mongoUri; + process.env.MONGODB_USER = mongoUri; app = (await import('./auth-service.js')).default; // Import app dynamically to ensure MONGODB_URI is set // Load database with initial conditions await addUser(user); diff --git a/users/userservice/package-lock.json b/users/userservice/package-lock.json index f89a7d6..f21b26c 100644 --- a/users/userservice/package-lock.json +++ b/users/userservice/package-lock.json @@ -11,8 +11,6 @@ "dependencies": { "bcrypt": "^5.1.1", "body-parser": "^1.20.2", - "cookie-parser": "^1.4.7", - "cors": "^2.8.5", "express": "^4.18.2", "mongoose": "^8.0.4" }, @@ -1906,28 +1904,6 @@ "node": ">= 0.6" } }, - "node_modules/cookie-parser": { - "version": "1.4.7", - "resolved": "https://registry.npmjs.org/cookie-parser/-/cookie-parser-1.4.7.tgz", - "integrity": "sha512-nGUvgXnotP3BsjiLX2ypbQnWoGUPIIfHQNZkkC668ntrzGWEZVW70HDEB1qnNGMicPje6EttlIgzo51YSwNQGw==", - "license": "MIT", - "dependencies": { - "cookie": "0.7.2", - "cookie-signature": "1.0.6" - }, - "engines": { - "node": ">= 0.8.0" - } - }, - "node_modules/cookie-parser/node_modules/cookie": { - "version": "0.7.2", - "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz", - "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, "node_modules/cookie-signature": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", @@ -1939,19 +1915,6 @@ "integrity": "sha512-LDx6oHrK+PhzLKJU9j5S7/Y3jM/mUHvD/DeI1WQmJn652iPC5Y4TBzC9l+5OMOXlyTTA+SmVUPm0HQUwpD5Jqw==", "dev": true }, - "node_modules/cors": { - "version": "2.8.5", - "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", - "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", - "license": "MIT", - "dependencies": { - "object-assign": "^4", - "vary": "^1" - }, - "engines": { - "node": ">= 0.10" - } - }, "node_modules/create-jest": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/create-jest/-/create-jest-29.7.0.tgz", diff --git a/users/userservice/package.json b/users/userservice/package.json index ac74b05..f02e73b 100644 --- a/users/userservice/package.json +++ b/users/userservice/package.json @@ -24,10 +24,8 @@ "dependencies": { "bcrypt": "^5.1.1", "body-parser": "^1.20.2", - "cors": "^2.8.5", "express": "^4.18.2", - "mongoose": "^8.0.4", - "cookie-parser": "^1.4.7" + "mongoose": "^8.0.4" }, "devDependencies": { "jest": "^29.7.0", diff --git a/users/userservice/user-service.js b/users/userservice/user-service.js index 70b0dde..d4163c3 100644 --- a/users/userservice/user-service.js +++ b/users/userservice/user-service.js @@ -1,24 +1,15 @@ // user-service.js import express from 'express'; import mongoose from 'mongoose'; -import cors from 'cors'; -import cookieParser from 'cookie-parser'; import userRouter from './user-router.js'; const app = express(); const port = 8001; -app.use( - cors({ - origin: 'http://localhost:8000', // Dirección del gateway. - credentials: true, // Permite enviar cookies. - }) -); app.use(express.json()); -app.use(cookieParser()); // Connect to MongoDB -const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/userdb'; +const mongoUri = process.env.MONGODB_USER || 'mongodb://localhost:27017/userdb'; mongoose.connect(mongoUri); // userRouter diff --git a/users/userservice/user-service.test.js b/users/userservice/user-service.test.js index 007fb00..0cac208 100644 --- a/users/userservice/user-service.test.js +++ b/users/userservice/user-service.test.js @@ -7,7 +7,7 @@ let app; beforeAll(async () => { mongoServer = await MongoMemoryServer.create(); const mongoUri = mongoServer.getUri(); - process.env.MONGODB_URI = mongoUri; + process.env.MONGODB_USER = mongoUri; app = (await import('./user-service.js')).default; // Import app dynamically to ensure MONGODB_URI is set }); diff --git a/webapp/e2e/test-environment-setup.js b/webapp/e2e/test-environment-setup.js index a152c9c..8cc7185 100644 --- a/webapp/e2e/test-environment-setup.js +++ b/webapp/e2e/test-environment-setup.js @@ -9,10 +9,12 @@ async function startServer() { console.log('Starting MongoDB memory server...'); mongoserver = await MongoMemoryServer.create(); const mongoUri = mongoserver.getUri(); - process.env.MONGODB_URI = mongoUri; + process.env.MONGODB_USER = mongoUri; - userservice = (await import('../../users/userservice/user-service.js')).default; - authservice = (await import('../../users/authservice/auth-service.js')).default; + userservice = (await import('../../users/userservice/user-service.js')) + .default; + authservice = (await import('../../users/authservice/auth-service.js')) + .default; gatewayservice = (await import('../../gatewayservice/gateway-service.js')) .default; }