From 844994d4713affa43c54ba99082bc08333af9f06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Mon, 2 May 2022 11:56:26 +0200 Subject: [PATCH 01/40] Arreglo cors y variables de entorno --- .github/workflows/pruebaDeploy.yml | 18 +++++++- restapi/.env | 2 +- restapi/.gitignore | 3 +- restapi/modules/gestorDB.ts | 5 +-- restapi/server.ts | 2 +- webapp/package-lock.json | 68 ++++++++++++++++++------------ 6 files changed, 62 insertions(+), 36 deletions(-) diff --git a/.github/workflows/pruebaDeploy.yml b/.github/workflows/pruebaDeploy.yml index 579d065..475b7ca 100644 --- a/.github/workflows/pruebaDeploy.yml +++ b/.github/workflows/pruebaDeploy.yml @@ -42,7 +42,11 @@ jobs: heroku_app_name: "dede-es2a-webapp" heroku_email: ${{ secrets.EMAIL }} usedocker: true - appdir: "webapp" + appdir: "webapp" + docker_build_args: | + API_URI + env: + API_URI: "https://dede-es2a-restapi.herokuapp.com" deploy-restapi: needs: [docker-push-restapi,docker-push-webapp] runs-on: ubuntu-latest @@ -55,4 +59,14 @@ jobs: heroku_app_name: "dede-es2a-restapi" heroku_email: ${{ secrets.EMAIL }} usedocker: true - appdir: "restapi" + appdir: "restapi" + docker_build_args: | + MONGO_URI + CLOUDINARY_NAME + CLOUDINARY_API_KEY + CLOUDINARY_API_SECRET + env: + MONGO_URI = {{secrets.MONGO_URI}} + CLOUDINARY_NAME={{secrets.CLOUD_NAME}} + CLOUDINARY_API_KEY={{secrets.CLOUD_KEY}} + CLOUDINARY_API_SECRET={{secrets.CLOUD_SECRET}} diff --git a/restapi/.env b/restapi/.env index b0afa91..b291959 100644 --- a/restapi/.env +++ b/restapi/.env @@ -1,4 +1,4 @@ -DB_CONNECT=mongodb+srv://admin:dede2a@tiendajuguetes.1s9n2.mongodb.net/myFirstDatabase?retryWrites=true&w=majority +MONGO_URI=mongodb+srv://admin:dede2a@tiendajuguetes.1s9n2.mongodb.net/myFirstDatabase?retryWrites=true&w=majority CLOUDINARY_NAME=dypp8pt31 CLOUDINARY_API_KEY=321597164512969 CLOUDINARY_API_SECRET=sM2uhnqaS53Sq9_HsPDLK63FS7I \ No newline at end of file diff --git a/restapi/.gitignore b/restapi/.gitignore index 30bc162..7af7f04 100644 --- a/restapi/.gitignore +++ b/restapi/.gitignore @@ -1 +1,2 @@ -/node_modules \ No newline at end of file +/node_modules +.env \ No newline at end of file diff --git a/restapi/modules/gestorDB.ts b/restapi/modules/gestorDB.ts index 0709b55..e719412 100644 --- a/restapi/modules/gestorDB.ts +++ b/restapi/modules/gestorDB.ts @@ -2,11 +2,8 @@ const mongoose = require('mongoose') require('dotenv').config() -const database_uri = process.env.DB_CONNECT -const database_test_uri = 'mongodb+srv://admin:@cluster.mf7ve.mongodb.net/myFirstDatabase?retryWrites=true&w=majority' - export function connect(){ - mongoose.connect('mongodb+srv://admin:dede2a@tiendajuguetes.1s9n2.mongodb.net/myFirstDatabase?retryWrites=true&w=majority', { + mongoose.connect(process.env.MONGO_URI, { }) .then(() =>{ diff --git a/restapi/server.ts b/restapi/server.ts index 2e64206..f6f307e 100644 --- a/restapi/server.ts +++ b/restapi/server.ts @@ -18,7 +18,7 @@ let {config} = require('./modules/cloudinary'); const options: cors.CorsOptions = { //origin: ['http://localhost:3000'] - origin: ['https://dede-es2a-webapp.herokuapp.com'] + origin: ['https://dede-es2a-webapp.herokuapp.com' || 'http://localhost:3000'] }; const metricsMiddleware:RequestHandler = promBundle({includeMethod: true}); diff --git a/webapp/package-lock.json b/webapp/package-lock.json index d497de0..6c0dd1e 100644 --- a/webapp/package-lock.json +++ b/webapp/package-lock.json @@ -49,7 +49,7 @@ "jest-cucumber": "^3.0.1", "jest-puppeteer": "^6.0.3", "puppeteer": "^13.0.1", - "react-scripts": "^5.0.0", + "react-scripts": "5.0.0", "start-server-and-test": "^1.14.0", "ts-jest": "^27.1.2", "ts-node-dev": "^1.1.8" @@ -2680,6 +2680,7 @@ "version": "28.0.1", "resolved": "https://registry.npmjs.org/@jest/console/-/console-28.0.1.tgz", "integrity": "sha512-c05/4ZS+1d/TM4svDxrsh+vbYUPC08C0zG/DWJgdv2rtkDgYHRfLtt9bSaWpSISE+NtqdRbnzbUtJeBXjTKyhQ==", + "dev": true, "dependencies": { "@jest/types": "^28.0.2", "@types/node": "*", @@ -2696,6 +2697,7 @@ "version": "28.0.1", "resolved": "https://registry.npmjs.org/@jest/types/-/types-28.0.1.tgz", "integrity": "sha512-Z48DBfQDtTZZAImaa1m8O1SCP9gx355FhuA6xuS8e7V5gQbj4l2hk/+EELN4UU/O9i5gjQuc94N/gC61/Qxfxw==", + "dev": true, "dependencies": { "@jest/schemas": "^28.0.2", "@types/istanbul-lib-coverage": "^2.0.0", @@ -2779,6 +2781,7 @@ "version": "28.0.1", "resolved": "https://registry.npmjs.org/jest-message-util/-/jest-message-util-28.0.1.tgz", "integrity": "sha512-Eb+s5Ow4MxcQb4gcIVWVdnLxCnaPrl6DZjOVe7MjKHhexmJlkVTdwvdC//YrAsJKWMU8eG2rdaGbgBk2zG2MLA==", + "dev": true, "dependencies": { "@babel/code-frame": "^7.12.13", "@jest/types": "^28.0.2", @@ -2798,6 +2801,7 @@ "version": "28.0.1", "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-28.0.1.tgz", "integrity": "sha512-gFpqWx9XqBmJRYqSnQ2FbpxWpvAU3TIGFQcfBrwnMVvwbB1ZHhhoQgS+oD0Ek61l9XkLsoWW20woaNlCRf4eMA==", + "dev": true, "dependencies": { "@jest/types": "^28.0.2", "@types/node": "*", @@ -2814,6 +2818,7 @@ "version": "28.0.1", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-28.0.1.tgz", "integrity": "sha512-utVSIy0ImophYyJALfiWULOeMnfoxLZEzii/92VcSzN7OX5U1r7erAMqfDJyuv31ugw4Rp5tOYUMndsZV1w8DQ==", + "dev": true, "dependencies": { "@jest/schemas": "^28.0.2", "ansi-regex": "^5.0.1", @@ -2839,7 +2844,8 @@ "node_modules/@jest/console/node_modules/react-is": { "version": "18.0.0", "resolved": "https://registry.npmjs.org/react-is/-/react-is-18.0.0.tgz", - "integrity": "sha512-yUcBYdBBbo3QiPsgYDcfQcIkGZHfxOaoE6HLSnr1sPzMhdyxusbfKOSUbSd/ocGi32dxcj366PsTj+5oggeKKw==" + "integrity": "sha512-yUcBYdBBbo3QiPsgYDcfQcIkGZHfxOaoE6HLSnr1sPzMhdyxusbfKOSUbSd/ocGi32dxcj366PsTj+5oggeKKw==", + "dev": true }, "node_modules/@jest/console/node_modules/supports-color": { "version": "7.2.0", @@ -3213,6 +3219,7 @@ "version": "28.0.0", "resolved": "https://registry.npmjs.org/@jest/schemas/-/schemas-28.0.0.tgz", "integrity": "sha512-Pap9Jvwr8KYFvDgkya/p0FCVya+jZkWt57lHpwBylfjgmwi/gtXfhyAO/Cw+jKuMafHcXY0beNf2XV2pkcu9vA==", + "dev": true, "dependencies": { "@sinclair/typebox": "^0.23.3" }, @@ -3245,6 +3252,7 @@ "version": "28.0.1", "resolved": "https://registry.npmjs.org/@jest/test-result/-/test-result-28.0.1.tgz", "integrity": "sha512-8LhoEbdIkkYK+PZx6JhfRvI1Jw7tfB77OEJUQwp0diBvXJpjPKeFFWfsbpm7djdXuKoKvXKNzSGgjXDOFbxuhg==", + "dev": true, "dependencies": { "@jest/console": "^28.0.2", "@jest/types": "^28.0.2", @@ -3259,6 +3267,7 @@ "version": "28.0.1", "resolved": "https://registry.npmjs.org/@jest/types/-/types-28.0.1.tgz", "integrity": "sha512-Z48DBfQDtTZZAImaa1m8O1SCP9gx355FhuA6xuS8e7V5gQbj4l2hk/+EELN4UU/O9i5gjQuc94N/gC61/Qxfxw==", + "dev": true, "dependencies": { "@jest/schemas": "^28.0.2", "@types/istanbul-lib-coverage": "^2.0.0", @@ -4340,7 +4349,8 @@ "node_modules/@sinclair/typebox": { "version": "0.23.4", "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.23.4.tgz", - "integrity": "sha512-0/WqSvpVbCBAV1yPeko7eAczKbs78dNVAaX14quVlwOb2wxfKuXCx91h4NrEfkYK9zEnyVSW4JVI/trP3iS+Qg==" + "integrity": "sha512-0/WqSvpVbCBAV1yPeko7eAczKbs78dNVAaX14quVlwOb2wxfKuXCx91h4NrEfkYK9zEnyVSW4JVI/trP3iS+Qg==", + "dev": true }, "node_modules/@sinonjs/commons": { "version": "1.8.3", @@ -12246,7 +12256,6 @@ "version": "5.0.0", "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz", "integrity": "sha512-EkYm5BcKUGiduxzSt3Eppko+PiNWNEpa4ySk9vTC6wDsQJW9rHSa+UhGNJoRYp7bz6Ht1eaRIa6QaJqO5rCFbA==", - "dev": true, "dependencies": { "agent-base": "6", "debug": "4" @@ -16306,6 +16315,7 @@ "version": "28.0.1", "resolved": "https://registry.npmjs.org/jest-watcher/-/jest-watcher-28.0.1.tgz", "integrity": "sha512-tKyjsQal10vBomcyn79ZTutv0N0/dSfYJ+WRFJ3nlaMejiDlLKjMGQ/QrcwcXIXMXQyt0tJG1ycmqLbJg5AK6A==", + "dev": true, "dependencies": { "@jest/test-result": "^28.0.2", "@jest/types": "^28.0.2", @@ -16324,6 +16334,7 @@ "version": "28.0.1", "resolved": "https://registry.npmjs.org/@jest/types/-/types-28.0.1.tgz", "integrity": "sha512-Z48DBfQDtTZZAImaa1m8O1SCP9gx355FhuA6xuS8e7V5gQbj4l2hk/+EELN4UU/O9i5gjQuc94N/gC61/Qxfxw==", + "dev": true, "dependencies": { "@jest/schemas": "^28.0.2", "@types/istanbul-lib-coverage": "^2.0.0", @@ -16407,6 +16418,7 @@ "version": "28.0.1", "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-28.0.1.tgz", "integrity": "sha512-gFpqWx9XqBmJRYqSnQ2FbpxWpvAU3TIGFQcfBrwnMVvwbB1ZHhhoQgS+oD0Ek61l9XkLsoWW20woaNlCRf4eMA==", + "dev": true, "dependencies": { "@jest/types": "^28.0.2", "@types/node": "*", @@ -27407,9 +27419,9 @@ "integrity": "sha512-ZXRY4jNvVgSVQ8DL3LTcakaAtXwTVUxE81hslsyD2AtoXW/wVob10HkOJ1X/pAlcI7D+2YoZKg5do8G/w6RYgA==" }, "@jest/console": { - "version": "28.0.1", - "resolved": "https://registry.npmjs.org/@jest/console/-/console-28.0.1.tgz", + "version": "https://registry.npmjs.org/@jest/console/-/console-28.0.1.tgz", "integrity": "sha512-c05/4ZS+1d/TM4svDxrsh+vbYUPC08C0zG/DWJgdv2rtkDgYHRfLtt9bSaWpSISE+NtqdRbnzbUtJeBXjTKyhQ==", + "dev": true, "requires": { "@jest/types": "^28.0.2", "@types/node": "*", @@ -27420,9 +27432,9 @@ }, "dependencies": { "@jest/types": { - "version": "28.0.1", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-28.0.1.tgz", + "version": "https://registry.npmjs.org/@jest/types/-/types-28.0.1.tgz", "integrity": "sha512-Z48DBfQDtTZZAImaa1m8O1SCP9gx355FhuA6xuS8e7V5gQbj4l2hk/+EELN4UU/O9i5gjQuc94N/gC61/Qxfxw==", + "dev": true, "requires": { "@jest/schemas": "^28.0.2", "@types/istanbul-lib-coverage": "^2.0.0", @@ -27482,9 +27494,9 @@ "dev": true }, "jest-message-util": { - "version": "28.0.1", - "resolved": "https://registry.npmjs.org/jest-message-util/-/jest-message-util-28.0.1.tgz", + "version": "https://registry.npmjs.org/jest-message-util/-/jest-message-util-28.0.1.tgz", "integrity": "sha512-Eb+s5Ow4MxcQb4gcIVWVdnLxCnaPrl6DZjOVe7MjKHhexmJlkVTdwvdC//YrAsJKWMU8eG2rdaGbgBk2zG2MLA==", + "dev": true, "requires": { "@babel/code-frame": "^7.12.13", "@jest/types": "^28.0.2", @@ -27498,9 +27510,9 @@ } }, "jest-util": { - "version": "28.0.1", - "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-28.0.1.tgz", + "version": "https://registry.npmjs.org/jest-util/-/jest-util-28.0.1.tgz", "integrity": "sha512-gFpqWx9XqBmJRYqSnQ2FbpxWpvAU3TIGFQcfBrwnMVvwbB1ZHhhoQgS+oD0Ek61l9XkLsoWW20woaNlCRf4eMA==", + "dev": true, "requires": { "@jest/types": "^28.0.2", "@types/node": "*", @@ -27511,9 +27523,9 @@ } }, "pretty-format": { - "version": "28.0.1", - "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-28.0.1.tgz", + "version": "https://registry.npmjs.org/pretty-format/-/pretty-format-28.0.1.tgz", "integrity": "sha512-utVSIy0ImophYyJALfiWULOeMnfoxLZEzii/92VcSzN7OX5U1r7erAMqfDJyuv31ugw4Rp5tOYUMndsZV1w8DQ==", + "dev": true, "requires": { "@jest/schemas": "^28.0.2", "ansi-regex": "^5.0.1", @@ -27532,7 +27544,8 @@ "react-is": { "version": "18.0.0", "resolved": "https://registry.npmjs.org/react-is/-/react-is-18.0.0.tgz", - "integrity": "sha512-yUcBYdBBbo3QiPsgYDcfQcIkGZHfxOaoE6HLSnr1sPzMhdyxusbfKOSUbSd/ocGi32dxcj366PsTj+5oggeKKw==" + "integrity": "sha512-yUcBYdBBbo3QiPsgYDcfQcIkGZHfxOaoE6HLSnr1sPzMhdyxusbfKOSUbSd/ocGi32dxcj366PsTj+5oggeKKw==", + "dev": true }, "supports-color": { "version": "7.2.0", @@ -27809,9 +27822,9 @@ } }, "@jest/schemas": { - "version": "28.0.0", - "resolved": "https://registry.npmjs.org/@jest/schemas/-/schemas-28.0.0.tgz", + "version": "https://registry.npmjs.org/@jest/schemas/-/schemas-28.0.0.tgz", "integrity": "sha512-Pap9Jvwr8KYFvDgkya/p0FCVya+jZkWt57lHpwBylfjgmwi/gtXfhyAO/Cw+jKuMafHcXY0beNf2XV2pkcu9vA==", + "dev": true, "requires": { "@sinclair/typebox": "^0.23.3" } @@ -27834,9 +27847,9 @@ } }, "@jest/test-result": { - "version": "28.0.1", - "resolved": "https://registry.npmjs.org/@jest/test-result/-/test-result-28.0.1.tgz", + "version": "https://registry.npmjs.org/@jest/test-result/-/test-result-28.0.1.tgz", "integrity": "sha512-8LhoEbdIkkYK+PZx6JhfRvI1Jw7tfB77OEJUQwp0diBvXJpjPKeFFWfsbpm7djdXuKoKvXKNzSGgjXDOFbxuhg==", + "dev": true, "requires": { "@jest/console": "^28.0.2", "@jest/types": "^28.0.2", @@ -27845,9 +27858,9 @@ }, "dependencies": { "@jest/types": { - "version": "28.0.1", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-28.0.1.tgz", + "version": "https://registry.npmjs.org/@jest/types/-/types-28.0.1.tgz", "integrity": "sha512-Z48DBfQDtTZZAImaa1m8O1SCP9gx355FhuA6xuS8e7V5gQbj4l2hk/+EELN4UU/O9i5gjQuc94N/gC61/Qxfxw==", + "dev": true, "requires": { "@jest/schemas": "^28.0.2", "@types/istanbul-lib-coverage": "^2.0.0", @@ -28538,7 +28551,8 @@ "@sinclair/typebox": { "version": "0.23.4", "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.23.4.tgz", - "integrity": "sha512-0/WqSvpVbCBAV1yPeko7eAczKbs78dNVAaX14quVlwOb2wxfKuXCx91h4NrEfkYK9zEnyVSW4JVI/trP3iS+Qg==" + "integrity": "sha512-0/WqSvpVbCBAV1yPeko7eAczKbs78dNVAaX14quVlwOb2wxfKuXCx91h4NrEfkYK9zEnyVSW4JVI/trP3iS+Qg==", + "dev": true }, "@sinonjs/commons": { "version": "1.8.3", @@ -34610,7 +34624,6 @@ "version": "5.0.0", "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz", "integrity": "sha512-EkYm5BcKUGiduxzSt3Eppko+PiNWNEpa4ySk9vTC6wDsQJW9rHSa+UhGNJoRYp7bz6Ht1eaRIa6QaJqO5rCFbA==", - "dev": true, "requires": { "agent-base": "6", "debug": "4" @@ -37650,6 +37663,7 @@ "version": "28.0.1", "resolved": "https://registry.npmjs.org/jest-watcher/-/jest-watcher-28.0.1.tgz", "integrity": "sha512-tKyjsQal10vBomcyn79ZTutv0N0/dSfYJ+WRFJ3nlaMejiDlLKjMGQ/QrcwcXIXMXQyt0tJG1ycmqLbJg5AK6A==", + "dev": true, "requires": { "@jest/test-result": "^28.0.2", "@jest/types": "^28.0.2", @@ -37662,9 +37676,9 @@ }, "dependencies": { "@jest/types": { - "version": "28.0.1", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-28.0.1.tgz", + "version": "https://registry.npmjs.org/@jest/types/-/types-28.0.1.tgz", "integrity": "sha512-Z48DBfQDtTZZAImaa1m8O1SCP9gx355FhuA6xuS8e7V5gQbj4l2hk/+EELN4UU/O9i5gjQuc94N/gC61/Qxfxw==", + "dev": true, "requires": { "@jest/schemas": "^28.0.2", "@types/istanbul-lib-coverage": "^2.0.0", @@ -37724,9 +37738,9 @@ "dev": true }, "jest-util": { - "version": "28.0.1", - "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-28.0.1.tgz", + "version": "https://registry.npmjs.org/jest-util/-/jest-util-28.0.1.tgz", "integrity": "sha512-gFpqWx9XqBmJRYqSnQ2FbpxWpvAU3TIGFQcfBrwnMVvwbB1ZHhhoQgS+oD0Ek61l9XkLsoWW20woaNlCRf4eMA==", + "dev": true, "requires": { "@jest/types": "^28.0.2", "@types/node": "*", From b7b91e32e9334479ab27b30ad98a540bc5b6349b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= <71430118+UO271728@users.noreply.github.com> Date: Mon, 2 May 2022 11:57:07 +0200 Subject: [PATCH 02/40] Delete .env --- restapi/.env | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 restapi/.env diff --git a/restapi/.env b/restapi/.env deleted file mode 100644 index b291959..0000000 --- a/restapi/.env +++ /dev/null @@ -1,4 +0,0 @@ -MONGO_URI=mongodb+srv://admin:dede2a@tiendajuguetes.1s9n2.mongodb.net/myFirstDatabase?retryWrites=true&w=majority -CLOUDINARY_NAME=dypp8pt31 -CLOUDINARY_API_KEY=321597164512969 -CLOUDINARY_API_SECRET=sM2uhnqaS53Sq9_HsPDLK63FS7I \ No newline at end of file From b08510a2ef68f716393c74895a50d668c156ed0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Mon, 2 May 2022 11:59:38 +0200 Subject: [PATCH 03/40] Arreglo workflow --- .github/workflows/pruebaDeploy.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pruebaDeploy.yml b/.github/workflows/pruebaDeploy.yml index 475b7ca..3cba929 100644 --- a/.github/workflows/pruebaDeploy.yml +++ b/.github/workflows/pruebaDeploy.yml @@ -61,12 +61,12 @@ jobs: usedocker: true appdir: "restapi" docker_build_args: | - MONGO_URI - CLOUDINARY_NAME - CLOUDINARY_API_KEY - CLOUDINARY_API_SECRET + MONGO_URI, + CLOUDINARY_NAME, + CLOUDINARY_API_KEY, + CLOUDINARY_API_SECRET, env: - MONGO_URI = {{secrets.MONGO_URI}} - CLOUDINARY_NAME={{secrets.CLOUD_NAME}} - CLOUDINARY_API_KEY={{secrets.CLOUD_KEY}} - CLOUDINARY_API_SECRET={{secrets.CLOUD_SECRET}} + MONGO_URI = {{secrets.MONGO_URI}}, + CLOUDINARY_NAME={{secrets.CLOUD_NAME}}, + CLOUDINARY_API_KEY={{secrets.CLOUD_KEY}}, + CLOUDINARY_API_SECRET={{secrets.CLOUD_SECRET}}, From 855cd1080ade81094e43a0364c30316714e9e36b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Mon, 2 May 2022 12:06:20 +0200 Subject: [PATCH 04/40] Seguir arreglando el workflow --- .github/workflows/pruebaDeploy.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pruebaDeploy.yml b/.github/workflows/pruebaDeploy.yml index 3cba929..888dc6c 100644 --- a/.github/workflows/pruebaDeploy.yml +++ b/.github/workflows/pruebaDeploy.yml @@ -66,7 +66,7 @@ jobs: CLOUDINARY_API_KEY, CLOUDINARY_API_SECRET, env: - MONGO_URI = {{secrets.MONGO_URI}}, - CLOUDINARY_NAME={{secrets.CLOUD_NAME}}, - CLOUDINARY_API_KEY={{secrets.CLOUD_KEY}}, - CLOUDINARY_API_SECRET={{secrets.CLOUD_SECRET}}, + MONGO_URI =${{secrets.MONGO_URI}}, + CLOUDINARY_NAME=${{secrets.CLOUD_NAME}}, + CLOUDINARY_API_KEY=${{secrets.CLOUD_KEY}}, + CLOUDINARY_API_SECRET=${{secrets.CLOUD_SECRET}}, From 9f2a10b01bdd6eddab469e82c89bc8d7f6f05b25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Mon, 2 May 2022 16:47:47 +0200 Subject: [PATCH 05/40] Arreglo minimo test y cambio en workflow --- .github/workflows/pruebaDeploy.yml | 20 ++++++++++---------- restapi/modules/gestorDB.ts | 6 +++--- restapi/routes/usuario.router.ts | 2 +- restapi/tests/datos/usuarios.json | 15 --------------- restapi/tests/pedido.test.ts | 2 +- restapi/tests/usuario.test.ts | 3 --- 6 files changed, 15 insertions(+), 33 deletions(-) diff --git a/.github/workflows/pruebaDeploy.yml b/.github/workflows/pruebaDeploy.yml index 888dc6c..d3aabb2 100644 --- a/.github/workflows/pruebaDeploy.yml +++ b/.github/workflows/pruebaDeploy.yml @@ -42,7 +42,7 @@ jobs: heroku_app_name: "dede-es2a-webapp" heroku_email: ${{ secrets.EMAIL }} usedocker: true - appdir: "webapp" + workdir: "webapp" docker_build_args: | API_URI env: @@ -59,14 +59,14 @@ jobs: heroku_app_name: "dede-es2a-restapi" heroku_email: ${{ secrets.EMAIL }} usedocker: true - appdir: "restapi" + workdir: "restapi" docker_build_args: | - MONGO_URI, - CLOUDINARY_NAME, - CLOUDINARY_API_KEY, - CLOUDINARY_API_SECRET, + MONGO_URI + CLOUDINARY_NAME + CLOUDINARY_API_KEY + CLOUDINARY_API_SECRET env: - MONGO_URI =${{secrets.MONGO_URI}}, - CLOUDINARY_NAME=${{secrets.CLOUD_NAME}}, - CLOUDINARY_API_KEY=${{secrets.CLOUD_KEY}}, - CLOUDINARY_API_SECRET=${{secrets.CLOUD_SECRET}}, + MONGO_URI =${{secrets.MONGO_URI}} + CLOUDINARY_NAME=${{secrets.CLOUD_NAME}} + CLOUDINARY_API_KEY=${{secrets.CLOUD_KEY}} + CLOUDINARY_API_SECRET=${{secrets.CLOUD_SECRET}} diff --git a/restapi/modules/gestorDB.ts b/restapi/modules/gestorDB.ts index e719412..ec7e961 100644 --- a/restapi/modules/gestorDB.ts +++ b/restapi/modules/gestorDB.ts @@ -4,12 +4,12 @@ require('dotenv').config() export function connect(){ mongoose.connect(process.env.MONGO_URI, { - + useNewUrlParser: true, + useUnifiedTopology: true }) .then(() =>{ console.log("Database connected") - }) - ; + }); } export function connectTest(){ diff --git a/restapi/routes/usuario.router.ts b/restapi/routes/usuario.router.ts index 2dda759..88177c2 100644 --- a/restapi/routes/usuario.router.ts +++ b/restapi/routes/usuario.router.ts @@ -23,7 +23,7 @@ usuarioRouter.get("/:email", async(req:Request,res:Response) =>{ if(usuario){ res.send(usuario); } else{ - res.send("No existe ese usuario"); + res.status(500).send("No existe ese usuario"); } } catch(error){ res.status(500).send("se ha producido un error"); diff --git a/restapi/tests/datos/usuarios.json b/restapi/tests/datos/usuarios.json index 59eeb7d..44c6562 100644 --- a/restapi/tests/datos/usuarios.json +++ b/restapi/tests/datos/usuarios.json @@ -1,32 +1,17 @@ [{ - "DNI":"12345678R", - "nombre":"admin", - "apellidos":"admin", "email":"admin@email.com", "isAdmin":true },{ - "DNI":"78958473Z", - "nombre":"Juan", - "apellidos":"Garcia", "email":"juan@email.com", "isAdmin":false },{ - "DNI":"25864789B", - "nombre":"Wardel Stephen", - "apellidos":"Curry", "email":"goat@email.com", "isAdmin":false }, { - "DNI":"257413698Y", - "nombre":"Carlos", - "apellidos":"Alcaraz", "email":"carlos@email.com", "isAdmin":false },{ - "DNI":"20506101F", - "nombre":"Fernando", - "apellidos":"Alonso", "email":"padre@email.com", "isAdmin":false }] \ No newline at end of file diff --git a/restapi/tests/pedido.test.ts b/restapi/tests/pedido.test.ts index 071b7ca..a999ae1 100644 --- a/restapi/tests/pedido.test.ts +++ b/restapi/tests/pedido.test.ts @@ -127,6 +127,6 @@ describe('pedidos ', () => { it("Se calculan los gastos de envío a una dirección que no se encuentra", async () =>{ const response:Response = await request(app).post('/pedido/gastosEnvio').send({direccion:"La direccion no se encuentra"}); expect(response.status).toBe(200); - expect(Number(response.text).toFixed(2).toString()).toEqual("5.00"); + expect(Number(response.text).toFixed(2).toString()).toEqual("0.00"); }); }); diff --git a/restapi/tests/usuario.test.ts b/restapi/tests/usuario.test.ts index 4e04ee4..0ec399c 100644 --- a/restapi/tests/usuario.test.ts +++ b/restapi/tests/usuario.test.ts @@ -69,9 +69,6 @@ describe('user ', () => { expect(response.statusCode).toBe(200); expect(response.body).toEqual({ id:response.body.id, - DNI:"20506101F", - nombre:"Fernando", - apellidos:"Alonso", email: "padre@email.com", isAdmin: false }); From da13bbb7329a413c7e1a94c17cbde1ddcc8366ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Mon, 2 May 2022 17:00:08 +0200 Subject: [PATCH 06/40] Commit de un guion --- .github/workflows/pruebaDeploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pruebaDeploy.yml b/.github/workflows/pruebaDeploy.yml index d3aabb2..4e57ba4 100644 --- a/.github/workflows/pruebaDeploy.yml +++ b/.github/workflows/pruebaDeploy.yml @@ -36,7 +36,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: Deploy webapp - uses: akhileshns/heroku-deploy@v3.12.12 + - uses: akhileshns/heroku-deploy@v3.12.12 with: heroku_api_key: ${{ secrets.DEPLOY_KEY }} heroku_app_name: "dede-es2a-webapp" @@ -53,7 +53,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: Deploy restapi - uses: akhileshns/heroku-deploy@v3.12.12 + - uses: akhileshns/heroku-deploy@v3.12.12 with: heroku_api_key: ${{ secrets.DEPLOY_KEY }} heroku_app_name: "dede-es2a-restapi" From d65febb29d747095ad7e03975c7585f0d5043577 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Mon, 2 May 2022 17:02:59 +0200 Subject: [PATCH 07/40] Mas correcciones --- .github/workflows/pruebaDeploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pruebaDeploy.yml b/.github/workflows/pruebaDeploy.yml index 4e57ba4..c4427c7 100644 --- a/.github/workflows/pruebaDeploy.yml +++ b/.github/workflows/pruebaDeploy.yml @@ -10,7 +10,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: Publish to Registry - uses: elgohr/Publish-Docker-Github-Action@3.04 + - uses: elgohr/Publish-Docker-Github-Action@3.04 with: name: arquisoft/dede_es2a/webapp username: ${{ github.actor }} @@ -23,7 +23,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: Publish to Registry - uses: elgohr/Publish-Docker-Github-Action@3.04 + - uses: elgohr/Publish-Docker-Github-Action@3.04 with: name: arquisoft/dede_es2a/restapi username: ${{ github.actor }} From 9c2dc35c59e19e6bfc2bfdc7f115d50f794453a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Mon, 2 May 2022 17:07:14 +0200 Subject: [PATCH 08/40] Prueba --- .github/workflows/pruebaDeploy.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pruebaDeploy.yml b/.github/workflows/pruebaDeploy.yml index c4427c7..d3aabb2 100644 --- a/.github/workflows/pruebaDeploy.yml +++ b/.github/workflows/pruebaDeploy.yml @@ -10,7 +10,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: Publish to Registry - - uses: elgohr/Publish-Docker-Github-Action@3.04 + uses: elgohr/Publish-Docker-Github-Action@3.04 with: name: arquisoft/dede_es2a/webapp username: ${{ github.actor }} @@ -23,7 +23,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: Publish to Registry - - uses: elgohr/Publish-Docker-Github-Action@3.04 + uses: elgohr/Publish-Docker-Github-Action@3.04 with: name: arquisoft/dede_es2a/restapi username: ${{ github.actor }} @@ -36,7 +36,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: Deploy webapp - - uses: akhileshns/heroku-deploy@v3.12.12 + uses: akhileshns/heroku-deploy@v3.12.12 with: heroku_api_key: ${{ secrets.DEPLOY_KEY }} heroku_app_name: "dede-es2a-webapp" @@ -53,7 +53,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: Deploy restapi - - uses: akhileshns/heroku-deploy@v3.12.12 + uses: akhileshns/heroku-deploy@v3.12.12 with: heroku_api_key: ${{ secrets.DEPLOY_KEY }} heroku_app_name: "dede-es2a-restapi" From beb257a00f84ecade4ab38ef2b929e63d3b6a730 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Mon, 2 May 2022 17:09:20 +0200 Subject: [PATCH 09/40] Error tonto --- .github/workflows/pruebaDeploy.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pruebaDeploy.yml b/.github/workflows/pruebaDeploy.yml index d3aabb2..420d40f 100644 --- a/.github/workflows/pruebaDeploy.yml +++ b/.github/workflows/pruebaDeploy.yml @@ -66,7 +66,7 @@ jobs: CLOUDINARY_API_KEY CLOUDINARY_API_SECRET env: - MONGO_URI =${{secrets.MONGO_URI}} - CLOUDINARY_NAME=${{secrets.CLOUD_NAME}} - CLOUDINARY_API_KEY=${{secrets.CLOUD_KEY}} - CLOUDINARY_API_SECRET=${{secrets.CLOUD_SECRET}} + MONGO_URI:${{secrets.MONGO_URI}} + CLOUDINARY_NAME:${{secrets.CLOUD_NAME}} + CLOUDINARY_API_KEY:${{secrets.CLOUD_KEY}} + CLOUDINARY_API_SECRET:${{secrets.CLOUD_SECRET}} From 42f5964b71b94be4840587390b67364443f2cb11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Mon, 2 May 2022 17:11:31 +0200 Subject: [PATCH 10/40] Error tonto 2 --- .github/workflows/pruebaDeploy.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pruebaDeploy.yml b/.github/workflows/pruebaDeploy.yml index 420d40f..149e895 100644 --- a/.github/workflows/pruebaDeploy.yml +++ b/.github/workflows/pruebaDeploy.yml @@ -66,7 +66,7 @@ jobs: CLOUDINARY_API_KEY CLOUDINARY_API_SECRET env: - MONGO_URI:${{secrets.MONGO_URI}} - CLOUDINARY_NAME:${{secrets.CLOUD_NAME}} - CLOUDINARY_API_KEY:${{secrets.CLOUD_KEY}} - CLOUDINARY_API_SECRET:${{secrets.CLOUD_SECRET}} + MONGO_URI: ${{secrets.MONGO_URI}} + CLOUDINARY_NAME: ${{secrets.CLOUD_NAME}} + CLOUDINARY_API_KEY: ${{secrets.CLOUD_KEY}} + CLOUDINARY_API_SECRET: ${{secrets.CLOUD_SECRET}} From ab3924eeed6d0cb93b34544f66b033f4edf81ab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Mon, 2 May 2022 17:21:21 +0200 Subject: [PATCH 11/40] Cambios por probar --- .github/workflows/pruebaDeploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pruebaDeploy.yml b/.github/workflows/pruebaDeploy.yml index 149e895..bfe8470 100644 --- a/.github/workflows/pruebaDeploy.yml +++ b/.github/workflows/pruebaDeploy.yml @@ -42,7 +42,7 @@ jobs: heroku_app_name: "dede-es2a-webapp" heroku_email: ${{ secrets.EMAIL }} usedocker: true - workdir: "webapp" + appdir: "webapp" docker_build_args: | API_URI env: @@ -59,7 +59,7 @@ jobs: heroku_app_name: "dede-es2a-restapi" heroku_email: ${{ secrets.EMAIL }} usedocker: true - workdir: "restapi" + appdir: "restapi" docker_build_args: | MONGO_URI CLOUDINARY_NAME From 6e10cb3e09ec414b8b13a83f2edc39e71025186b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Mon, 2 May 2022 17:41:59 +0200 Subject: [PATCH 12/40] =?UTF-8?q?Creaci=C3=B3n=20de=20variables=20en=20str?= =?UTF-8?q?ing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/pruebaDeploy.yml | 2 +- restapi/modules/cloudinary.ts | 16 ++++++++++------ restapi/modules/gestorDB.ts | 4 +++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pruebaDeploy.yml b/.github/workflows/pruebaDeploy.yml index bfe8470..bf02c18 100644 --- a/.github/workflows/pruebaDeploy.yml +++ b/.github/workflows/pruebaDeploy.yml @@ -69,4 +69,4 @@ jobs: MONGO_URI: ${{secrets.MONGO_URI}} CLOUDINARY_NAME: ${{secrets.CLOUD_NAME}} CLOUDINARY_API_KEY: ${{secrets.CLOUD_KEY}} - CLOUDINARY_API_SECRET: ${{secrets.CLOUD_SECRET}} + CLOUDINARY_API_SECRET: ${{secrets.CLOUD_SECRET}} \ No newline at end of file diff --git a/restapi/modules/cloudinary.ts b/restapi/modules/cloudinary.ts index 6cd9e67..cb921f5 100644 --- a/restapi/modules/cloudinary.ts +++ b/restapi/modules/cloudinary.ts @@ -1,23 +1,27 @@ const cloudinary = require('cloudinary').v2; require('dotenv').config() -/* +var name: string = process.env.CLOUDINARY_NAME || 'name' +var api_key:string = process.env.CLOUDINARY_API_KEY || 'key' +var secret:string = process.env.CLOUDINARY_API_SECRET || 'secret' + export function config(){ cloudinary.config({ - cloud_name : process.env.CLOUDINARY_NAME, - api_key : process.env.CLOUDINARY_API_KEY, - api_secret: process.env.CLOUDINARY_API_SECRET + cloud_name : name, + api_key : api_key, + api_secret: secret }); -}*/ +} +/* export function config(){ cloudinary.config({ cloud_name : 'dypp8pt31', api_key : '321597164512969', api_secret: 'sM2uhnqaS53Sq9_HsPDLK63FS7I' }); -} +}*/ export function configTest(){ diff --git a/restapi/modules/gestorDB.ts b/restapi/modules/gestorDB.ts index ec7e961..db0173b 100644 --- a/restapi/modules/gestorDB.ts +++ b/restapi/modules/gestorDB.ts @@ -2,8 +2,10 @@ const mongoose = require('mongoose') require('dotenv').config() +const mongo_uri:string = process.env.MONGO_URI || 'localhost' + export function connect(){ - mongoose.connect(process.env.MONGO_URI, { + mongoose.connect(mongo_uri, { useNewUrlParser: true, useUnifiedTopology: true }) From b30c815fae0b3b096fa158ea5926d10adc675616 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Mon, 2 May 2022 18:01:22 +0200 Subject: [PATCH 13/40] =?UTF-8?q?A=C3=B1adir=20principio=20mongo=20a=20la?= =?UTF-8?q?=20url?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- restapi/modules/gestorDB.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/restapi/modules/gestorDB.ts b/restapi/modules/gestorDB.ts index db0173b..b743456 100644 --- a/restapi/modules/gestorDB.ts +++ b/restapi/modules/gestorDB.ts @@ -2,7 +2,7 @@ const mongoose = require('mongoose') require('dotenv').config() -const mongo_uri:string = process.env.MONGO_URI || 'localhost' +const mongo_uri:string = process.env.MONGO_URI || 'mongodb+srv://localhost' export function connect(){ mongoose.connect(mongo_uri, { From 1b2a06e51f815680fabfa97acaa0d378990c341f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Mon, 2 May 2022 18:16:23 +0200 Subject: [PATCH 14/40] Cambiando la uri de otra opcion --- restapi/modules/gestorDB.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/restapi/modules/gestorDB.ts b/restapi/modules/gestorDB.ts index b743456..3fa878c 100644 --- a/restapi/modules/gestorDB.ts +++ b/restapi/modules/gestorDB.ts @@ -2,7 +2,7 @@ const mongoose = require('mongoose') require('dotenv').config() -const mongo_uri:string = process.env.MONGO_URI || 'mongodb+srv://localhost' +const mongo_uri:string = process.env.MONGO_URI || 'mongodb+srv://localhost:123456' export function connect(){ mongoose.connect(mongo_uri, { From ccf567f5c41b6a9f633a9204f33180962cdb5483 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Mon, 2 May 2022 18:31:11 +0200 Subject: [PATCH 15/40] Ultimo intento --- .github/workflows/pruebaDeploy.yml | 30 ------------------------------ restapi/modules/gestorDB.ts | 3 +-- 2 files changed, 1 insertion(+), 32 deletions(-) diff --git a/.github/workflows/pruebaDeploy.yml b/.github/workflows/pruebaDeploy.yml index bf02c18..b83931a 100644 --- a/.github/workflows/pruebaDeploy.yml +++ b/.github/workflows/pruebaDeploy.yml @@ -4,19 +4,6 @@ on: types: [published] jobs: - docker-push-webapp: - name: Push webapp Docker Image to GitHub Packages - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Publish to Registry - uses: elgohr/Publish-Docker-Github-Action@3.04 - with: - name: arquisoft/dede_es2a/webapp - username: ${{ github.actor }} - password: ${{ secrets.DOCKER_PUSH_TOKEN }} - registry: ghcr.io - workdir: webapp docker-push-restapi: name: Push restapi Docker Image to GitHub Packages runs-on: ubuntu-latest @@ -30,23 +17,6 @@ jobs: password: ${{ secrets.DOCKER_PUSH_TOKEN }} registry: ghcr.io workdir: restapi - deploy-webapp: - needs: [docker-push-restapi,docker-push-webapp] - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Deploy webapp - uses: akhileshns/heroku-deploy@v3.12.12 - with: - heroku_api_key: ${{ secrets.DEPLOY_KEY }} - heroku_app_name: "dede-es2a-webapp" - heroku_email: ${{ secrets.EMAIL }} - usedocker: true - appdir: "webapp" - docker_build_args: | - API_URI - env: - API_URI: "https://dede-es2a-restapi.herokuapp.com" deploy-restapi: needs: [docker-push-restapi,docker-push-webapp] runs-on: ubuntu-latest diff --git a/restapi/modules/gestorDB.ts b/restapi/modules/gestorDB.ts index 3fa878c..fb08fd5 100644 --- a/restapi/modules/gestorDB.ts +++ b/restapi/modules/gestorDB.ts @@ -2,10 +2,9 @@ const mongoose = require('mongoose') require('dotenv').config() -const mongo_uri:string = process.env.MONGO_URI || 'mongodb+srv://localhost:123456' export function connect(){ - mongoose.connect(mongo_uri, { + mongoose.connect(process.env.MONGO_URI!, { useNewUrlParser: true, useUnifiedTopology: true }) From 76f43503f9ca2cdc42f06f8297ebaff9608002ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Mon, 2 May 2022 18:35:01 +0200 Subject: [PATCH 16/40] Cambio en el workflow --- .github/workflows/pruebaDeploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pruebaDeploy.yml b/.github/workflows/pruebaDeploy.yml index b83931a..67ab6e2 100644 --- a/.github/workflows/pruebaDeploy.yml +++ b/.github/workflows/pruebaDeploy.yml @@ -18,7 +18,7 @@ jobs: registry: ghcr.io workdir: restapi deploy-restapi: - needs: [docker-push-restapi,docker-push-webapp] + needs: [docker-push-restapi] runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 From 2b438a16e8f390192e6754804d2909de3d882274 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Mon, 2 May 2022 18:42:29 +0200 Subject: [PATCH 17/40] No se me ocurre mas --- restapi/modules/gestorDB.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/restapi/modules/gestorDB.ts b/restapi/modules/gestorDB.ts index fb08fd5..4fe50d5 100644 --- a/restapi/modules/gestorDB.ts +++ b/restapi/modules/gestorDB.ts @@ -2,9 +2,10 @@ const mongoose = require('mongoose') require('dotenv').config() +const uri: string = process.env.MONGO_URI!; export function connect(){ - mongoose.connect(process.env.MONGO_URI!, { + mongoose.connect(uri, { useNewUrlParser: true, useUnifiedTopology: true }) From b0a5205aeb624f213c4f3124f7c558784b3d64cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Mon, 2 May 2022 20:27:01 +0200 Subject: [PATCH 18/40] Cambio de uri --- restapi/modules/gestorDB.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/restapi/modules/gestorDB.ts b/restapi/modules/gestorDB.ts index 4fe50d5..b61c72a 100644 --- a/restapi/modules/gestorDB.ts +++ b/restapi/modules/gestorDB.ts @@ -2,10 +2,10 @@ const mongoose = require('mongoose') require('dotenv').config() -const uri: string = process.env.MONGO_URI!; + export function connect(){ - mongoose.connect(uri, { + mongoose.connect(process.env.MONGO_URI!, { useNewUrlParser: true, useUnifiedTopology: true }) From 434ef629f0f54e10cc31639188f32889b1e370ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Mon, 2 May 2022 21:00:41 +0200 Subject: [PATCH 19/40] Prueba completa --- .github/workflows/pruebaDeploy.yml | 50 ++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/.github/workflows/pruebaDeploy.yml b/.github/workflows/pruebaDeploy.yml index 67ab6e2..7ffb561 100644 --- a/.github/workflows/pruebaDeploy.yml +++ b/.github/workflows/pruebaDeploy.yml @@ -4,9 +4,24 @@ on: types: [published] jobs: + docker-push-webapp: + name: Push webapp Docker Image to GitHub Packages + runs-on: ubuntu-latest + needs: [e2e-tests] + steps: + - uses: actions/checkout@v2 + - name: Publish to Registry + uses: elgohr/Publish-Docker-Github-Action@3.04 + with: + name: arquisoft/dede_es2a/webapp + username: ${{ github.actor }} + password: ${{ secrets.DOCKER_PUSH_TOKEN }} + registry: ghcr.io + appdir: webapp docker-push-restapi: name: Push restapi Docker Image to GitHub Packages runs-on: ubuntu-latest + needs: [e2e-tests] steps: - uses: actions/checkout@v2 - name: Publish to Registry @@ -16,27 +31,30 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.DOCKER_PUSH_TOKEN }} registry: ghcr.io - workdir: restapi + appdir: restapi + deploy-webapp: + needs: [docker-push-restapi,docker-push-webapp] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Deploy webapp + uses: akhileshns/heroku-deploy@v3.12.12 + with: + heroku_api_key: ${{ secrets.DEPLOY_HOST }} + heroku_app_name: ${{ secrets.DEPLOY_USER }} + heroku_email: ${{ secrets.DEPLOY_KEY }} + usedocker: true + appdir: "webapp" deploy-restapi: - needs: [docker-push-restapi] + needs: [docker-push-restapi,docker-push-webapp] runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Deploy restapi uses: akhileshns/heroku-deploy@v3.12.12 with: - heroku_api_key: ${{ secrets.DEPLOY_KEY }} - heroku_app_name: "dede-es2a-restapi" - heroku_email: ${{ secrets.EMAIL }} + heroku_api_key: ${{ secrets.DEPLOY_HOST }} + heroku_app_name: ${{ secrets.DEPLOY_USER }} + heroku_email: ${{ secrets.DEPLOY_KEY }} usedocker: true - appdir: "restapi" - docker_build_args: | - MONGO_URI - CLOUDINARY_NAME - CLOUDINARY_API_KEY - CLOUDINARY_API_SECRET - env: - MONGO_URI: ${{secrets.MONGO_URI}} - CLOUDINARY_NAME: ${{secrets.CLOUD_NAME}} - CLOUDINARY_API_KEY: ${{secrets.CLOUD_KEY}} - CLOUDINARY_API_SECRET: ${{secrets.CLOUD_SECRET}} \ No newline at end of file + appdir: "restapi" \ No newline at end of file From 876fdd5aeb77baf522c4f6b3fe4b7d2739d5e440 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Mon, 2 May 2022 21:02:30 +0200 Subject: [PATCH 20/40] Error tonto 3 --- .github/workflows/pruebaDeploy.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/pruebaDeploy.yml b/.github/workflows/pruebaDeploy.yml index 7ffb561..f5f828e 100644 --- a/.github/workflows/pruebaDeploy.yml +++ b/.github/workflows/pruebaDeploy.yml @@ -7,7 +7,6 @@ jobs: docker-push-webapp: name: Push webapp Docker Image to GitHub Packages runs-on: ubuntu-latest - needs: [e2e-tests] steps: - uses: actions/checkout@v2 - name: Publish to Registry @@ -21,7 +20,6 @@ jobs: docker-push-restapi: name: Push restapi Docker Image to GitHub Packages runs-on: ubuntu-latest - needs: [e2e-tests] steps: - uses: actions/checkout@v2 - name: Publish to Registry From 05fe8b1d4d84107c3aef211d9fac8db214e75598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Mon, 2 May 2022 21:09:09 +0200 Subject: [PATCH 21/40] Vuelta al antiguo workflow --- .github/workflows/pruebaDeploy.yml | 40 ++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/.github/workflows/pruebaDeploy.yml b/.github/workflows/pruebaDeploy.yml index f5f828e..eb7d5ba 100644 --- a/.github/workflows/pruebaDeploy.yml +++ b/.github/workflows/pruebaDeploy.yml @@ -8,7 +8,7 @@ jobs: name: Push webapp Docker Image to GitHub Packages runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - user: actions/checkoout@v2 - name: Publish to Registry uses: elgohr/Publish-Docker-Github-Action@3.04 with: @@ -16,7 +16,7 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.DOCKER_PUSH_TOKEN }} registry: ghcr.io - appdir: webapp + workdir: webapp docker-push-restapi: name: Push restapi Docker Image to GitHub Packages runs-on: ubuntu-latest @@ -29,20 +29,24 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.DOCKER_PUSH_TOKEN }} registry: ghcr.io - appdir: restapi - deploy-webapp: + workdir: restapi + deploy-restapi: needs: [docker-push-restapi,docker-push-webapp] runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: Deploy webapp + - name: Deploy restapi uses: akhileshns/heroku-deploy@v3.12.12 with: - heroku_api_key: ${{ secrets.DEPLOY_HOST }} - heroku_app_name: ${{ secrets.DEPLOY_USER }} - heroku_email: ${{ secrets.DEPLOY_KEY }} + heroku_api_key: ${{ secrets.DEPLOY_KEY }} + heroku_app_name: "dede-es2a-webapp" + heroku_email: ${{ secrets.EMAIL }} usedocker: true - appdir: "webapp" + appdir: "webapp" + docker_build_args: | + API_URI + env: + API_URI: "https://dede-es2a-restapi.herokuapp.com/" deploy-restapi: needs: [docker-push-restapi,docker-push-webapp] runs-on: ubuntu-latest @@ -51,8 +55,18 @@ jobs: - name: Deploy restapi uses: akhileshns/heroku-deploy@v3.12.12 with: - heroku_api_key: ${{ secrets.DEPLOY_HOST }} - heroku_app_name: ${{ secrets.DEPLOY_USER }} - heroku_email: ${{ secrets.DEPLOY_KEY }} + heroku_api_key: ${{ secrets.DEPLOY_KEY }} + heroku_app_name: "dede-es2a-restapi" + heroku_email: ${{ secrets.EMAIL }} usedocker: true - appdir: "restapi" \ No newline at end of file + appdir: "restapi" + docker_build_args: | + MONGO_URI + CLOUDINARY_NAME + CLOUDINARY_API_KEY + CLOUDINARY_API_SECRET + env: + MONGO_URI: ${{secrets.MONGO_URI}} + CLOUDINARY_NAME: ${{secrets.CLOUD_NAME}} + CLOUDINARY_API_KEY: ${{secrets.CLOUD_KEY}} + CLOUDINARY_API_SECRET: ${{secrets.CLOUD_SECRET}} \ No newline at end of file From f5df0688c21dadfb247ceca2809305ee80633381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Mon, 2 May 2022 21:10:46 +0200 Subject: [PATCH 22/40] Antiguo --- .github/workflows/pruebaDeploy.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pruebaDeploy.yml b/.github/workflows/pruebaDeploy.yml index eb7d5ba..8ada502 100644 --- a/.github/workflows/pruebaDeploy.yml +++ b/.github/workflows/pruebaDeploy.yml @@ -8,7 +8,7 @@ jobs: name: Push webapp Docker Image to GitHub Packages runs-on: ubuntu-latest steps: - - user: actions/checkoout@v2 + - uses: actions/checkout@v2 - name: Publish to Registry uses: elgohr/Publish-Docker-Github-Action@3.04 with: @@ -30,23 +30,23 @@ jobs: password: ${{ secrets.DOCKER_PUSH_TOKEN }} registry: ghcr.io workdir: restapi - deploy-restapi: + deploy-webapp: needs: [docker-push-restapi,docker-push-webapp] runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: Deploy restapi + - name: Deploy webapp uses: akhileshns/heroku-deploy@v3.12.12 with: heroku_api_key: ${{ secrets.DEPLOY_KEY }} heroku_app_name: "dede-es2a-webapp" heroku_email: ${{ secrets.EMAIL }} usedocker: true - appdir: "webapp" + appdir: "webapp" docker_build_args: | API_URI env: - API_URI: "https://dede-es2a-restapi.herokuapp.com/" + API_URI: "https://dede-es2a-restapi.herokuapp.com/" deploy-restapi: needs: [docker-push-restapi,docker-push-webapp] runs-on: ubuntu-latest From 144f39fa8f58dd36a245aef7928e8673113ae17d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Mon, 2 May 2022 23:17:45 +0200 Subject: [PATCH 23/40] Otro intento --- .github/workflows/pruebaDeploy.yml | 12 ++++++------ webapp/src/App.tsx | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pruebaDeploy.yml b/.github/workflows/pruebaDeploy.yml index 8ada502..1cde7be 100644 --- a/.github/workflows/pruebaDeploy.yml +++ b/.github/workflows/pruebaDeploy.yml @@ -44,9 +44,9 @@ jobs: usedocker: true appdir: "webapp" docker_build_args: | - API_URI + REACT_APP_API_URI env: - API_URI: "https://dede-es2a-restapi.herokuapp.com/" + REACT_APP_API_URI: "https://dede-es2a-restapi.herokuapp.com/" deploy-restapi: needs: [docker-push-restapi,docker-push-webapp] runs-on: ubuntu-latest @@ -66,7 +66,7 @@ jobs: CLOUDINARY_API_KEY CLOUDINARY_API_SECRET env: - MONGO_URI: ${{secrets.MONGO_URI}} - CLOUDINARY_NAME: ${{secrets.CLOUD_NAME}} - CLOUDINARY_API_KEY: ${{secrets.CLOUD_KEY}} - CLOUDINARY_API_SECRET: ${{secrets.CLOUD_SECRET}} \ No newline at end of file + MONGO_URI: ${{ secrets.MONGO_URI }} + CLOUDINARY_NAME: ${{ secrets.CLOUD_NAME }} + CLOUDINARY_API_KEY: ${{ secrets.CLOUD_KEY }} + CLOUDINARY_API_SECRET: ${{ secrets.CLOUD_SECRET }} \ No newline at end of file diff --git a/webapp/src/App.tsx b/webapp/src/App.tsx index 837059b..23dc6d1 100644 --- a/webapp/src/App.tsx +++ b/webapp/src/App.tsx @@ -162,7 +162,7 @@ const App = () => { //Coloca una barra de carga cuando la página está cargando - if (isLoading) return ; + //if (isLoading) return ; //if (error) return
Algo ha fallado
; //console.log('aaaaaaaaaaa \n aaaaaaaaaaaa \n aaaaaaaaaaaaaaa'); From 8ec5a331b09ca21b87044fe7a3c4fd8db9b8cdae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Tue, 3 May 2022 00:02:23 +0200 Subject: [PATCH 24/40] Cambiando url --- webapp/src/App.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/webapp/src/App.tsx b/webapp/src/App.tsx index 23dc6d1..75f16b6 100644 --- a/webapp/src/App.tsx +++ b/webapp/src/App.tsx @@ -56,8 +56,8 @@ export type Juguete = { // AÑADIDO--------------------------------------------------------------------------------------------- // Petición para obtener todos los juguetes de la base de datos export async function getJuguetes(): Promise { - const apiEndPoint = process.env.REACT_APP_API_URI || 'http://localhost:5000/' - //const apiEndPoint= process.env.REACT_APP_API_URI || 'https://dede-en2a-restapi.herokuapp.com' + //const apiEndPoint = process.env.REACT_APP_API_URI || 'http://localhost:5000/' + const apiEndPoint= process.env.REACT_APP_API_URI || 'https://dede-es2a-restapi.herokuapp.com/' let response = await fetch(apiEndPoint + 'juguete/withstock'); //The objects returned by the api are directly convertible to User objects //console.log(response.json()); @@ -65,8 +65,8 @@ export async function getJuguetes(): Promise { } export async function getJuguetesCategoria(): Promise { - const apiEndPoint = process.env.REACT_APP_API_URI || 'http://localhost:5000/' - //const apiEndPoint= process.env.REACT_APP_API_URI || 'https://dede-en2a-restapi.herokuapp.com' + //const apiEndPoint = process.env.REACT_APP_API_URI || 'http://localhost:5000/' + const apiEndPoint= process.env.REACT_APP_API_URI || 'https://dede-es2a-restapi.herokuapp.com/' let response = await fetch(apiEndPoint + 'juguete/categoria/nostalgia'); //The objects returned by the api are directly convertible to User objects //console.log(response.json()); From aca60535943e4df870c0ff52b0720bf2d689eedf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Tue, 3 May 2022 12:49:46 +0200 Subject: [PATCH 25/40] Probar varaible entorno --- .../src/componentes/editarProducto/editarProducto.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/webapp/src/componentes/editarProducto/editarProducto.tsx b/webapp/src/componentes/editarProducto/editarProducto.tsx index 84ab333..e4381a2 100644 --- a/webapp/src/componentes/editarProducto/editarProducto.tsx +++ b/webapp/src/componentes/editarProducto/editarProducto.tsx @@ -12,10 +12,9 @@ var categoria: string; var precio: number; async function getJuguete(): Promise { - const apiEndPoint = process.env.REACT_APP_API_URI || 'http://localhost:5000/' - //const apiEndPoint= process.env.REACT_APP_API_URI || 'https://dede-en2a-restapi.herokuapp.com' + //const apiEndPoint = process.env.REACT_APP_API_URI || 'http://localhost:5000/' + const apiEndPoint = process.env.API_URL || 'http://localhost:5000/' let partes = url.split('/'); - //console.log(partes[partes.length - 1]); let response = await fetch(apiEndPoint + "juguete/" + partes[partes.length - 1]); //The objects returned by the api are directly convertible to User objects let j = response.json(); @@ -24,8 +23,9 @@ async function getJuguete(): Promise { } async function updateJuguete(): Promise { - const apiEndPoint = process.env.REACT_APP_API_URI || 'http://localhost:5000/' - //const apiEndPoint= process.env.REACT_APP_API_URI || 'https://dede-en2a-restapi.herokuapp.com' + const apiEndPoint = process.env.API_URL || 'http://localhost:5000/' + //console.log(process.env.REACT_APP_API_URI) + //const apiEndPoint = process.env.REACT_APP_API_URI || 'https://dede-es2a-restapi.herokuapp.com/' let partes = url.split('/'); let response = await fetch(apiEndPoint + "juguete/update/" + partes[partes.length - 1], { method: 'POST', From 6d306dcf8707108f358389829457250d3af91916 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Tue, 3 May 2022 13:13:21 +0200 Subject: [PATCH 26/40] Probar API_URL --- webapp/src/App.tsx | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/webapp/src/App.tsx b/webapp/src/App.tsx index 5e565d4..05430d0 100644 --- a/webapp/src/App.tsx +++ b/webapp/src/App.tsx @@ -57,8 +57,8 @@ export type Juguete = { // AÑADIDO--------------------------------------------------------------------------------------------- // Petición para obtener todos los juguetes de la base de datos export async function getJuguetes(): Promise { - //const apiEndPoint = process.env.REACT_APP_API_URI || 'http://localhost:5000/' - const apiEndPoint= process.env.REACT_APP_API_URI || 'https://dede-es2a-restapi.herokuapp.com/' + const apiEndPoint = process.env.API_URL || 'http://localhost:5000/' + //const apiEndPoint= process.env.REACT_APP_API_URI || 'https://dede-es2a-restapi.herokuapp.com/' let response = await fetch(apiEndPoint + 'juguete/withstock'); //The objects returned by the api are directly convertible to User objects //console.log(response.json()); @@ -80,7 +80,7 @@ const App = () => { //const {data, isLoading, error} =useQuery('products', getProducts); //AÑADIDO---------------------------------------------------------------------- - const { data, isLoading } = useQuery('juguetes', getJuguetes); + const { data } = useQuery('juguetes', getJuguetes); useEffect(() => { @@ -154,10 +154,6 @@ const App = () => { }; - //Coloca una barra de carga cuando la página está cargando - if (isLoading) return ; - //if (error) return
Algo ha fallado
; - return ( <> From 48d74da71b335bb35c1baee7c2d7c3683556d70f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Tue, 3 May 2022 13:47:19 +0200 Subject: [PATCH 27/40] Probar a sacar las llamadas a la api a api.ts --- restapi/server.ts | 6 +++--- webapp/src/App.tsx | 13 +++---------- webapp/src/api/api.ts | 11 +++++++++++ 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/restapi/server.ts b/restapi/server.ts index f6f307e..f93363c 100644 --- a/restapi/server.ts +++ b/restapi/server.ts @@ -17,8 +17,8 @@ let bd = require('./modules/gestorDB') let {config} = require('./modules/cloudinary'); const options: cors.CorsOptions = { - //origin: ['http://localhost:3000'] - origin: ['https://dede-es2a-webapp.herokuapp.com' || 'http://localhost:3000'] + origin: ['http://localhost:3000'] + //origin: 'https://dede-es2a-webapp.herokuapp.com' || 'http://localhost:3000' }; const metricsMiddleware:RequestHandler = promBundle({includeMethod: true}); @@ -27,7 +27,7 @@ app.use(metricsMiddleware); bd.connect(); config(); -app.use(cors(options)); +app.use(cors()); app.use(bp.json()); app.use("/juguete", jugueteRouter); diff --git a/webapp/src/App.tsx b/webapp/src/App.tsx index 05430d0..c74ff78 100644 --- a/webapp/src/App.tsx +++ b/webapp/src/App.tsx @@ -28,6 +28,8 @@ import ProcesoPago from './PayForm/ProcesoPago'; import EditForm from './componentes/editarProducto/editarProducto'; import CategoriesBar from './PayForm/CategoriesBar'; import AddForm from './componentes/nuevoProducto/nuevoProducto'; +import {getJuguetes} from './api/api'; + //Types export type CartItemType = { @@ -54,16 +56,7 @@ export type Juguete = { -// AÑADIDO--------------------------------------------------------------------------------------------- -// Petición para obtener todos los juguetes de la base de datos -export async function getJuguetes(): Promise { - const apiEndPoint = process.env.API_URL || 'http://localhost:5000/' - //const apiEndPoint= process.env.REACT_APP_API_URI || 'https://dede-es2a-restapi.herokuapp.com/' - let response = await fetch(apiEndPoint + 'juguete/withstock'); - //The objects returned by the api are directly convertible to User objects - //console.log(response.json()); - return response.json(); -} + /*Tambien se ha añadido la entidad compartida 'Juguete' en la carpeta shared, creando un type con el esquema de juguete en la BD y exportando para poder usarlo desde fuera*/ diff --git a/webapp/src/api/api.ts b/webapp/src/api/api.ts index 966ba1e..5b84314 100644 --- a/webapp/src/api/api.ts +++ b/webapp/src/api/api.ts @@ -1,4 +1,5 @@ import {User} from '../shared/shareddtypes'; +import { Juguete } from '../shared/sharedJuguete'; export async function addUser(user:User):Promise{ const apiEndPoint= process.env.REACT_APP_API_URI || 'http://localhost:5000/api' @@ -13,6 +14,16 @@ export async function addUser(user:User):Promise{ return false; } +export async function getJuguetes(): Promise { + const apiEndPoint = process.env.REACT_APP_API_URI || 'http://localhost:5000/' + console.log(process.env.REACT_APP_API_URI) + //const apiEndPoint= process.env.REACT_APP_API_URI || 'https://dede-es2a-restapi.herokuapp.com/' + let response = await fetch(apiEndPoint + 'juguete/withstock'); + //The objects returned by the api are directly convertible to User objects + //console.log(response.json()); + return response.json(); +} + export async function getUsers():Promise{ const apiEndPoint= process.env.REACT_APP_API_URI || 'http://localhost:5000/api' let response = await fetch(apiEndPoint+'/users/list'); From f4d538dc255c850a5fc3e9caaff5ea8f179f7ddc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Tue, 3 May 2022 13:47:39 +0200 Subject: [PATCH 28/40] Console --- webapp/src/api/api.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/webapp/src/api/api.ts b/webapp/src/api/api.ts index 5b84314..98b58b1 100644 --- a/webapp/src/api/api.ts +++ b/webapp/src/api/api.ts @@ -16,7 +16,6 @@ export async function addUser(user:User):Promise{ export async function getJuguetes(): Promise { const apiEndPoint = process.env.REACT_APP_API_URI || 'http://localhost:5000/' - console.log(process.env.REACT_APP_API_URI) //const apiEndPoint= process.env.REACT_APP_API_URI || 'https://dede-es2a-restapi.herokuapp.com/' let response = await fetch(apiEndPoint + 'juguete/withstock'); //The objects returned by the api are directly convertible to User objects From 21094a7471952a766f9b7300bd8a183903fdd933 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Tue, 3 May 2022 15:16:24 +0200 Subject: [PATCH 29/40] Cambiando a API_URI --- .github/workflows/pruebaDeploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pruebaDeploy.yml b/.github/workflows/pruebaDeploy.yml index f030692..e60c88d 100644 --- a/.github/workflows/pruebaDeploy.yml +++ b/.github/workflows/pruebaDeploy.yml @@ -43,9 +43,9 @@ jobs: usedocker: true appdir: "webapp" docker_build_args: | - REACT_APP_API_URI + API_URI env: - REACT_APP_API_URI: "https://dede-es2a-restapi.herokuapp.com/" + API_URI: "https://dede-es2a-restapi.herokuapp.com/" deploy-restapi: needs: [docker-push-restapi,docker-push-webapp] runs-on: ubuntu-latest From 7dcc40c90f64537e77ea62a76023b53dadab65e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Tue, 3 May 2022 15:49:39 +0200 Subject: [PATCH 30/40] Cambiando el dockerfile --- .github/workflows/pruebaDeploy.yml | 2 +- webapp/Dockerfile | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pruebaDeploy.yml b/.github/workflows/pruebaDeploy.yml index e60c88d..e76e64a 100644 --- a/.github/workflows/pruebaDeploy.yml +++ b/.github/workflows/pruebaDeploy.yml @@ -45,7 +45,7 @@ jobs: docker_build_args: | API_URI env: - API_URI: "https://dede-es2a-restapi.herokuapp.com/" + API_URI: "https://dede-es2a-restapi.herokuapp.com" deploy-restapi: needs: [docker-push-restapi,docker-push-webapp] runs-on: ubuntu-latest diff --git a/webapp/Dockerfile b/webapp/Dockerfile index bca5e82..f2a0654 100644 --- a/webapp/Dockerfile +++ b/webapp/Dockerfile @@ -5,6 +5,8 @@ WORKDIR /app #Install the dependencies RUN npm install +ARG API_URI = "http://localhost:5000" +ENV REACT_APP_API_URI=$API_URI #Crete an optimized version of the webapp RUN npm run build From a553f60352ec0ccced8ed2f27244dd1eed37311e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Tue, 3 May 2022 16:13:59 +0200 Subject: [PATCH 31/40] =?UTF-8?q?A=C3=B1adiendo=20ARG=20en=20dockerfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/pruebaDeploy.yml | 25 ++++++++++--------------- restapi/Dockerfile | 12 ++++++++++++ 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/.github/workflows/pruebaDeploy.yml b/.github/workflows/pruebaDeploy.yml index e76e64a..1e1411b 100644 --- a/.github/workflows/pruebaDeploy.yml +++ b/.github/workflows/pruebaDeploy.yml @@ -6,6 +6,8 @@ jobs: docker-push-webapp: name: Push webapp Docker Image to GitHub Packages runs-on: ubuntu-latest + env: + API_URI: "https://dede-es2a-restapi.herokuapp.com" steps: - uses: actions/checkout@v2 - name: Publish to Registry @@ -16,9 +18,15 @@ jobs: password: ${{ secrets.DOCKER_PUSH_TOKEN }} registry: ghcr.io workdir: webapp + buildargs: API_URI docker-push-restapi: name: Push restapi Docker Image to GitHub Packages runs-on: ubuntu-latest + env: + MONGO_URI: ${{ secrets.MONGO_URI }} + CLOUDINARY_NAME: ${{ secrets.CLOUD_NAME }} + CLOUDINARY_API_KEY: ${{ secrets.CLOUD_KEY }} + CLOUDINARY_API_SECRET: ${{ secrets.CLOUD_SECRET}} steps: - uses: actions/checkout@v2 - name: Publish to Registry @@ -29,6 +37,7 @@ jobs: password: ${{ secrets.DOCKER_PUSH_TOKEN }} registry: ghcr.io workdir: restapi + buildargs: MONGO_URI, CLOUDINARY_NAME, CLOUDINARY_API_KEY, CLOUDINARY_API_SECRET deploy-webapp: needs: [docker-push-restapi,docker-push-webapp] runs-on: ubuntu-latest @@ -42,10 +51,6 @@ jobs: heroku_email: ${{ secrets.EMAIL }} usedocker: true appdir: "webapp" - docker_build_args: | - API_URI - env: - API_URI: "https://dede-es2a-restapi.herokuapp.com" deploy-restapi: needs: [docker-push-restapi,docker-push-webapp] runs-on: ubuntu-latest @@ -58,14 +63,4 @@ jobs: heroku_app_name: "dede-es2a-restapi" heroku_email: ${{ secrets.EMAIL }} usedocker: true - appdir: "restapi" - docker_build_args: | - MONGO_URI - CLOUDINARY_NAME - CLOUDINARY_API_KEY - CLOUDINARY_API_SECRET - env: - MONGO_URI: ${{ secrets.MONGO_URI }} - CLOUDINARY_NAME: ${{ secrets.CLOUD_NAME }} - CLOUDINARY_API_KEY: ${{ secrets.CLOUD_KEY }} - CLOUDINARY_API_SECRET: ${{ secrets.CLOUD_SECRET }} \ No newline at end of file + appdir: "restapi" \ No newline at end of file diff --git a/restapi/Dockerfile b/restapi/Dockerfile index e5a95f8..f584c0f 100644 --- a/restapi/Dockerfile +++ b/restapi/Dockerfile @@ -3,6 +3,18 @@ LABEL org.opencontainers.image.source https://github.com/Arquisoft/dede_es2a COPY . /app WORKDIR /app +ARG MONGO_URI="mongodb://mongoserver:27017/api" +ENV MONGO_URI= $MONGO_URI + +ARG CLOUDINARY_NAME="name" +ENV CLOUDINARY_NAME= $CLOUDINARY_NAME + +ARG CLOUDINARY_API_KEY= "apikey" +ENV CLOUDINARY_API_KEY= $CLOUDINARY_NAME + +ARG CLOUDINARY_API_SECRET= "secret" +ENV CLOUDINARY_API_SECRET= $CLOUDINARY_API_SECRET + #Install the dependencies RUN npm install From 59b27585c6cd6b5a46d8cc8dd92efdfb29c895ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Tue, 3 May 2022 16:21:09 +0200 Subject: [PATCH 32/40] Intentando entender --- restapi/Dockerfile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/restapi/Dockerfile b/restapi/Dockerfile index f584c0f..21e5856 100644 --- a/restapi/Dockerfile +++ b/restapi/Dockerfile @@ -4,16 +4,16 @@ COPY . /app WORKDIR /app ARG MONGO_URI="mongodb://mongoserver:27017/api" -ENV MONGO_URI= $MONGO_URI +ENV MONGO_URI=$MONGO_URI ARG CLOUDINARY_NAME="name" -ENV CLOUDINARY_NAME= $CLOUDINARY_NAME +ENV CLOUDINARY_NAME=$CLOUDINARY_NAME -ARG CLOUDINARY_API_KEY= "apikey" -ENV CLOUDINARY_API_KEY= $CLOUDINARY_NAME +ARG CLOUDINARY_API_KEY="apikey" +ENV CLOUDINARY_API_KEY=$CLOUDINARY_NAME -ARG CLOUDINARY_API_SECRET= "secret" -ENV CLOUDINARY_API_SECRET= $CLOUDINARY_API_SECRET +ARG CLOUDINARY_API_SECRET="secret" +ENV CLOUDINARY_API_SECRET=$CLOUDINARY_API_SECRET #Install the dependencies From f0a91f5763c92db312578824b883d1dffdc23f56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Tue, 3 May 2022 16:24:57 +0200 Subject: [PATCH 33/40] Otro mas --- .github/workflows/pruebaDeploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pruebaDeploy.yml b/.github/workflows/pruebaDeploy.yml index 1e1411b..fc0bbed 100644 --- a/.github/workflows/pruebaDeploy.yml +++ b/.github/workflows/pruebaDeploy.yml @@ -7,7 +7,7 @@ jobs: name: Push webapp Docker Image to GitHub Packages runs-on: ubuntu-latest env: - API_URI: "https://dede-es2a-restapi.herokuapp.com" + API_URI: https://dede-es2a-restapi.herokuapp.com steps: - uses: actions/checkout@v2 - name: Publish to Registry From e4e8f1fcc67183485577277c603400d3ce4abe74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Tue, 3 May 2022 16:49:51 +0200 Subject: [PATCH 34/40] Cambiando a un .env --- .github/workflows/pruebaDeploy.yml | 9 --------- restapi/Dockerfile | 13 ------------- webapp/Dockerfile | 3 --- webapp/package.json | 16 +++++----------- webapp/src/api/api.ts | 7 ++++--- 5 files changed, 9 insertions(+), 39 deletions(-) diff --git a/.github/workflows/pruebaDeploy.yml b/.github/workflows/pruebaDeploy.yml index fc0bbed..9b52778 100644 --- a/.github/workflows/pruebaDeploy.yml +++ b/.github/workflows/pruebaDeploy.yml @@ -6,8 +6,6 @@ jobs: docker-push-webapp: name: Push webapp Docker Image to GitHub Packages runs-on: ubuntu-latest - env: - API_URI: https://dede-es2a-restapi.herokuapp.com steps: - uses: actions/checkout@v2 - name: Publish to Registry @@ -18,15 +16,9 @@ jobs: password: ${{ secrets.DOCKER_PUSH_TOKEN }} registry: ghcr.io workdir: webapp - buildargs: API_URI docker-push-restapi: name: Push restapi Docker Image to GitHub Packages runs-on: ubuntu-latest - env: - MONGO_URI: ${{ secrets.MONGO_URI }} - CLOUDINARY_NAME: ${{ secrets.CLOUD_NAME }} - CLOUDINARY_API_KEY: ${{ secrets.CLOUD_KEY }} - CLOUDINARY_API_SECRET: ${{ secrets.CLOUD_SECRET}} steps: - uses: actions/checkout@v2 - name: Publish to Registry @@ -37,7 +29,6 @@ jobs: password: ${{ secrets.DOCKER_PUSH_TOKEN }} registry: ghcr.io workdir: restapi - buildargs: MONGO_URI, CLOUDINARY_NAME, CLOUDINARY_API_KEY, CLOUDINARY_API_SECRET deploy-webapp: needs: [docker-push-restapi,docker-push-webapp] runs-on: ubuntu-latest diff --git a/restapi/Dockerfile b/restapi/Dockerfile index 21e5856..51c6283 100644 --- a/restapi/Dockerfile +++ b/restapi/Dockerfile @@ -3,19 +3,6 @@ LABEL org.opencontainers.image.source https://github.com/Arquisoft/dede_es2a COPY . /app WORKDIR /app -ARG MONGO_URI="mongodb://mongoserver:27017/api" -ENV MONGO_URI=$MONGO_URI - -ARG CLOUDINARY_NAME="name" -ENV CLOUDINARY_NAME=$CLOUDINARY_NAME - -ARG CLOUDINARY_API_KEY="apikey" -ENV CLOUDINARY_API_KEY=$CLOUDINARY_NAME - -ARG CLOUDINARY_API_SECRET="secret" -ENV CLOUDINARY_API_SECRET=$CLOUDINARY_API_SECRET - - #Install the dependencies RUN npm install diff --git a/webapp/Dockerfile b/webapp/Dockerfile index f2a0654..e26f7ce 100644 --- a/webapp/Dockerfile +++ b/webapp/Dockerfile @@ -5,9 +5,6 @@ WORKDIR /app #Install the dependencies RUN npm install -ARG API_URI = "http://localhost:5000" -ENV REACT_APP_API_URI=$API_URI - #Crete an optimized version of the webapp RUN npm run build diff --git a/webapp/package.json b/webapp/package.json index 842e37b..088ba26 100644 --- a/webapp/package.json +++ b/webapp/package.json @@ -20,6 +20,7 @@ "@types/react": "^17.0.37", "@types/react-dom": "^17.0.11", "@types/styled-components": "^5.1.24", + "dotenv": "^16.0.0", "express": "^4.17.2", "jest": "^27.4.7", "jest-puppeteer": "^6.1.0", @@ -63,24 +64,17 @@ ] }, "devDependencies": { - "@types/expect-puppeteer": "^4.4.7", - "@types/express": "^4.17.13", - "@types/jest": "^27.4.0", "@types/puppeteer": "^5.4.4", "expect-puppeteer": "^6.0.2", "jest-cucumber": "^3.0.1", "jest-puppeteer": "^6.0.3", "puppeteer": "^13.0.1", - "react-scripts": "^5.0.0", + "react-scripts": "5.0.0", "start-server-and-test": "^1.14.0", "ts-jest": "^27.1.2", - "ts-node-dev": "^1.1.8", - - "react-scripts": "5.0.0" - - } - - } + "ts-node-dev": "^1.1.8" + } +} diff --git a/webapp/src/api/api.ts b/webapp/src/api/api.ts index 98b58b1..688efe9 100644 --- a/webapp/src/api/api.ts +++ b/webapp/src/api/api.ts @@ -1,8 +1,9 @@ import {User} from '../shared/shareddtypes'; import { Juguete } from '../shared/sharedJuguete'; +require('dotenv').config(); export async function addUser(user:User):Promise{ - const apiEndPoint= process.env.REACT_APP_API_URI || 'http://localhost:5000/api' + const apiEndPoint= process.env.API_URI || 'http://localhost:5000/api' let response = await fetch(apiEndPoint+'/users/add', { method: 'POST', headers: {'Content-Type':'application/json'}, @@ -15,7 +16,7 @@ export async function addUser(user:User):Promise{ } export async function getJuguetes(): Promise { - const apiEndPoint = process.env.REACT_APP_API_URI || 'http://localhost:5000/' + const apiEndPoint = process.env.API_URI || 'http://localhost:5000/' //const apiEndPoint= process.env.REACT_APP_API_URI || 'https://dede-es2a-restapi.herokuapp.com/' let response = await fetch(apiEndPoint + 'juguete/withstock'); //The objects returned by the api are directly convertible to User objects @@ -24,7 +25,7 @@ export async function getJuguetes(): Promise { } export async function getUsers():Promise{ - const apiEndPoint= process.env.REACT_APP_API_URI || 'http://localhost:5000/api' + const apiEndPoint= process.env.API_URI || 'http://localhost:5000/api' let response = await fetch(apiEndPoint+'/users/list'); //The objects returned by the api are directly convertible to User objects return response.json() From bbd924fe224c7c7c3988c92d3eb6e74e649913a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Tue, 3 May 2022 17:10:09 +0200 Subject: [PATCH 35/40] Cambio completo --- .../{pruebaDeploy.yml => pruebaDeploy.ts} | 4 +- .github/workflows/pruebaSinDocker.yml | 46 +++++++++++++++++++ restapi/Dockerfile | 13 ++++++ webapp/Dockerfile | 3 ++ webapp/src/api/api.ts | 7 ++- 5 files changed, 68 insertions(+), 5 deletions(-) rename .github/workflows/{pruebaDeploy.yml => pruebaDeploy.ts} (97%) create mode 100644 .github/workflows/pruebaSinDocker.yml diff --git a/.github/workflows/pruebaDeploy.yml b/.github/workflows/pruebaDeploy.ts similarity index 97% rename from .github/workflows/pruebaDeploy.yml rename to .github/workflows/pruebaDeploy.ts index 9b52778..5e2a46e 100644 --- a/.github/workflows/pruebaDeploy.yml +++ b/.github/workflows/pruebaDeploy.ts @@ -1,3 +1,4 @@ +/* name: CI for ASW2122 on: release: @@ -54,4 +55,5 @@ jobs: heroku_app_name: "dede-es2a-restapi" heroku_email: ${{ secrets.EMAIL }} usedocker: true - appdir: "restapi" \ No newline at end of file + appdir: "restapi" + */ \ No newline at end of file diff --git a/.github/workflows/pruebaSinDocker.yml b/.github/workflows/pruebaSinDocker.yml new file mode 100644 index 0000000..55cac92 --- /dev/null +++ b/.github/workflows/pruebaSinDocker.yml @@ -0,0 +1,46 @@ +/* +name: CI for ASW2122 +on: + release: + types: [published] +jobs: + deploy-webapp: + needs: [docker-push-restapi,docker-push-webapp] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Deploy webapp + uses: akhileshns/heroku-deploy@v3.12.12 + with: + heroku_api_key: ${{ secrets.DEPLOY_KEY }} + heroku_app_name: "dede-es2a-webapp" + heroku_email: ${{ secrets.EMAIL }} + usedocker: true + appdir: "webapp" + docker_build_args: | + API_URI + env: + API_URI: "https://dede-es2a-restapi.herokuapp.com/" + deploy-restapi: + needs: [docker-push-restapi,docker-push-webapp] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Deploy restapi + uses: akhileshns/heroku-deploy@v3.12.12 + with: + heroku_api_key: ${{ secrets.DEPLOY_KEY }} + heroku_app_name: "dede-es2a-restapi" + heroku_email: ${{ secrets.EMAIL }} + usedocker: true + appdir: "restapi" + docker_build_args: | + MONGO_URI + CLOUDINARY_NAME + CLOUDINARY_API_KEY + CLOUDINARY_API_SECRET + env: + MONGO_URI: ${{ secrets.MONGO_URI }} + CLOUDINARY_NAME: ${{ secrets.CLOUD_NAME }} + CLOUDINARY_API_KEY: ${{ secrets.CLOUD_KEY }} + CLOUDINARY_API_SECRET: ${{ secrets.CLOUD_SECRET }} \ No newline at end of file diff --git a/restapi/Dockerfile b/restapi/Dockerfile index 51c6283..21e5856 100644 --- a/restapi/Dockerfile +++ b/restapi/Dockerfile @@ -3,6 +3,19 @@ LABEL org.opencontainers.image.source https://github.com/Arquisoft/dede_es2a COPY . /app WORKDIR /app +ARG MONGO_URI="mongodb://mongoserver:27017/api" +ENV MONGO_URI=$MONGO_URI + +ARG CLOUDINARY_NAME="name" +ENV CLOUDINARY_NAME=$CLOUDINARY_NAME + +ARG CLOUDINARY_API_KEY="apikey" +ENV CLOUDINARY_API_KEY=$CLOUDINARY_NAME + +ARG CLOUDINARY_API_SECRET="secret" +ENV CLOUDINARY_API_SECRET=$CLOUDINARY_API_SECRET + + #Install the dependencies RUN npm install diff --git a/webapp/Dockerfile b/webapp/Dockerfile index e26f7ce..fbac2eb 100644 --- a/webapp/Dockerfile +++ b/webapp/Dockerfile @@ -5,6 +5,9 @@ WORKDIR /app #Install the dependencies RUN npm install +ARG API_URI="http://localhost:5000" +ENV REACT_APP_API_URI=$API_URI + #Crete an optimized version of the webapp RUN npm run build diff --git a/webapp/src/api/api.ts b/webapp/src/api/api.ts index 688efe9..d7faa27 100644 --- a/webapp/src/api/api.ts +++ b/webapp/src/api/api.ts @@ -1,9 +1,8 @@ import {User} from '../shared/shareddtypes'; import { Juguete } from '../shared/sharedJuguete'; -require('dotenv').config(); export async function addUser(user:User):Promise{ - const apiEndPoint= process.env.API_URI || 'http://localhost:5000/api' + const apiEndPoint= process.env.REACT_APP_API_URI || 'http://localhost:5000/api' let response = await fetch(apiEndPoint+'/users/add', { method: 'POST', headers: {'Content-Type':'application/json'}, @@ -16,9 +15,9 @@ export async function addUser(user:User):Promise{ } export async function getJuguetes(): Promise { - const apiEndPoint = process.env.API_URI || 'http://localhost:5000/' + const apiEndPoint = process.env.REACT_APP_API_URI || 'http://localhost:5000/' //const apiEndPoint= process.env.REACT_APP_API_URI || 'https://dede-es2a-restapi.herokuapp.com/' - let response = await fetch(apiEndPoint + 'juguete/withstock'); + let response = await fetch(apiEndPoint + '/juguete/withstock'); //The objects returned by the api are directly convertible to User objects //console.log(response.json()); return response.json(); From 4078c060406b86287dff1054cbb1b42fa8c4de92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Tue, 3 May 2022 17:10:49 +0200 Subject: [PATCH 36/40] Error tonto --- .github/workflows/pruebaSinDocker.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/pruebaSinDocker.yml b/.github/workflows/pruebaSinDocker.yml index 55cac92..32c04ca 100644 --- a/.github/workflows/pruebaSinDocker.yml +++ b/.github/workflows/pruebaSinDocker.yml @@ -1,4 +1,3 @@ -/* name: CI for ASW2122 on: release: From 8be12a8d226fae8c13a14f504254269ee5b3f06b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= <71430118+UO271728@users.noreply.github.com> Date: Tue, 3 May 2022 17:12:53 +0200 Subject: [PATCH 37/40] Update pruebaSinDocker.yml --- .github/workflows/pruebaSinDocker.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/pruebaSinDocker.yml b/.github/workflows/pruebaSinDocker.yml index 32c04ca..01cd1d6 100644 --- a/.github/workflows/pruebaSinDocker.yml +++ b/.github/workflows/pruebaSinDocker.yml @@ -4,7 +4,6 @@ on: types: [published] jobs: deploy-webapp: - needs: [docker-push-restapi,docker-push-webapp] runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -21,7 +20,6 @@ jobs: env: API_URI: "https://dede-es2a-restapi.herokuapp.com/" deploy-restapi: - needs: [docker-push-restapi,docker-push-webapp] runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -42,4 +40,4 @@ jobs: MONGO_URI: ${{ secrets.MONGO_URI }} CLOUDINARY_NAME: ${{ secrets.CLOUD_NAME }} CLOUDINARY_API_KEY: ${{ secrets.CLOUD_KEY }} - CLOUDINARY_API_SECRET: ${{ secrets.CLOUD_SECRET }} \ No newline at end of file + CLOUDINARY_API_SECRET: ${{ secrets.CLOUD_SECRET }} From 59b8507c79e87559547a68815a4a91db59c0d650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Tue, 3 May 2022 17:26:28 +0200 Subject: [PATCH 38/40] Moviendo las peticiones --- webapp/src/App.tsx | 12 ++++++++---- webapp/src/api/api.ts | 8 -------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/webapp/src/App.tsx b/webapp/src/App.tsx index c74ff78..5d0b79a 100644 --- a/webapp/src/App.tsx +++ b/webapp/src/App.tsx @@ -28,7 +28,6 @@ import ProcesoPago from './PayForm/ProcesoPago'; import EditForm from './componentes/editarProducto/editarProducto'; import CategoriesBar from './PayForm/CategoriesBar'; import AddForm from './componentes/nuevoProducto/nuevoProducto'; -import {getJuguetes} from './api/api'; //Types @@ -54,9 +53,14 @@ export type Juguete = { } */ - - - +export async function getJuguetes(): Promise { + const apiEndPoint = process.env.REACT_APP_API_URI || 'http://localhost:5000/' + //const apiEndPoint= process.env.REACT_APP_API_URI || 'https://dede-es2a-restapi.herokuapp.com/' + let response = await fetch(apiEndPoint + '/juguete/withstock'); + //The objects returned by the api are directly convertible to User objects + //console.log(response.json()); + return response.json(); +} /*Tambien se ha añadido la entidad compartida 'Juguete' en la carpeta shared, creando un type con el esquema de juguete en la BD y exportando para poder usarlo desde fuera*/ diff --git a/webapp/src/api/api.ts b/webapp/src/api/api.ts index d7faa27..2b1f33e 100644 --- a/webapp/src/api/api.ts +++ b/webapp/src/api/api.ts @@ -14,14 +14,6 @@ export async function addUser(user:User):Promise{ return false; } -export async function getJuguetes(): Promise { - const apiEndPoint = process.env.REACT_APP_API_URI || 'http://localhost:5000/' - //const apiEndPoint= process.env.REACT_APP_API_URI || 'https://dede-es2a-restapi.herokuapp.com/' - let response = await fetch(apiEndPoint + '/juguete/withstock'); - //The objects returned by the api are directly convertible to User objects - //console.log(response.json()); - return response.json(); -} export async function getUsers():Promise{ const apiEndPoint= process.env.API_URI || 'http://localhost:5000/api' From 97345161ccc7559beeb37c998a8fe89edc3a1172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Tue, 3 May 2022 17:27:55 +0200 Subject: [PATCH 39/40] Quitar la barra --- .github/workflows/pruebaSinDocker.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/pruebaSinDocker.yml b/.github/workflows/pruebaSinDocker.yml index 32c04ca..dafa354 100644 --- a/.github/workflows/pruebaSinDocker.yml +++ b/.github/workflows/pruebaSinDocker.yml @@ -4,7 +4,6 @@ on: types: [published] jobs: deploy-webapp: - needs: [docker-push-restapi,docker-push-webapp] runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -19,9 +18,8 @@ jobs: docker_build_args: | API_URI env: - API_URI: "https://dede-es2a-restapi.herokuapp.com/" + API_URI: "https://dede-es2a-restapi.herokuapp.com" deploy-restapi: - needs: [docker-push-restapi,docker-push-webapp] runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 From 4c469939e3b442261e3d8815b27cb278af2d7889 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1iz?= Date: Tue, 3 May 2022 17:45:07 +0200 Subject: [PATCH 40/40] Adaptar direcciones --- webapp/src/Item/Item.tsx | 5 +++-- webapp/src/PayForm/ProcesoPago.tsx | 4 +++- webapp/src/componentes/Pedidos/historial.tsx | 6 +++--- webapp/src/componentes/editarProducto/editarProducto.tsx | 2 +- webapp/src/componentes/nuevoProducto/nuevoProducto.tsx | 6 +++--- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/webapp/src/Item/Item.tsx b/webapp/src/Item/Item.tsx index 6559b39..f4675c1 100644 --- a/webapp/src/Item/Item.tsx +++ b/webapp/src/Item/Item.tsx @@ -21,9 +21,10 @@ type Props = { } async function addStock(nombre: string): Promise { - const apiEndPoint = process.env.REACT_APP_API_URI || 'http://localhost:5000/' + //const apiEndPoint = process.env.REACT_APP_API_URI || 'http://localhost:5000/' + const apiEndPoint = process.env.REACT_APP_API_URI || 'https://dede-es2a-restapi.herokuapp.com/' //let response = - await fetch(apiEndPoint + 'juguete/addStock/' + nombre, { + await fetch(apiEndPoint + '/juguete/addStock/' + nombre, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ "stock": 10 }) diff --git a/webapp/src/PayForm/ProcesoPago.tsx b/webapp/src/PayForm/ProcesoPago.tsx index 79a76cd..da34ec7 100644 --- a/webapp/src/PayForm/ProcesoPago.tsx +++ b/webapp/src/PayForm/ProcesoPago.tsx @@ -44,7 +44,8 @@ async function finalizarPedido(precioGastosDeEnvio: string, juguetes: Juguete[], var price: number; price = calculateTotal(juguetes); const apiEndPoint = process.env.REACT_APP_API_URI || 'http://localhost:5000/' - let response = await fetch(apiEndPoint + 'pedido', { + //const apiEndPoint = process.env.REACT_APP_API_URI || 'https://dede-es2a-restapi.herokuapp.com/' + let response = await fetch(apiEndPoint + '/pedido', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ @@ -60,6 +61,7 @@ async function finalizarPedido(precioGastosDeEnvio: string, juguetes: Juguete[], // Petición para obtener los gastos de envio async function getGastosEnvio(): Promise { const apiEndPoint = process.env.REACT_APP_API_URI || 'http://localhost:5000/' + //const apiEndPoint = process.env.REACT_APP_API_URI || 'https://dede-es2a-restapi.herokuapp.com/' let response = await fetch(apiEndPoint + 'pedido/gastosEnvio/', { method: 'POST', headers: { 'Content-Type': 'application/json' }, diff --git a/webapp/src/componentes/Pedidos/historial.tsx b/webapp/src/componentes/Pedidos/historial.tsx index c58451b..a4f7a98 100644 --- a/webapp/src/componentes/Pedidos/historial.tsx +++ b/webapp/src/componentes/Pedidos/historial.tsx @@ -7,9 +7,9 @@ var correo: string; var numero: number; async function getPedidos(): Promise { - const apiEndPoint = process.env.REACT_APP_API_URI || 'http://localhost:5000/' - //const apiEndPoint= process.env.REACT_APP_API_URI || 'https://dede-en2a-restapi.herokuapp.com' - let response = await fetch(apiEndPoint + "pedido/byUser/" + correo); + //const apiEndPoint = process.env.REACT_APP_API_URI || 'http://localhost:5000/' + const apiEndPoint = process.env.REACT_APP_API_URI || 'https://dede-es2a-restapi.herokuapp.com/' + let response = await fetch(apiEndPoint + "/pedido/byUser/" + correo); //The objects returned by the api are directly convertible to User objects return response.json(); diff --git a/webapp/src/componentes/editarProducto/editarProducto.tsx b/webapp/src/componentes/editarProducto/editarProducto.tsx index e4381a2..65a6a12 100644 --- a/webapp/src/componentes/editarProducto/editarProducto.tsx +++ b/webapp/src/componentes/editarProducto/editarProducto.tsx @@ -15,7 +15,7 @@ async function getJuguete(): Promise { //const apiEndPoint = process.env.REACT_APP_API_URI || 'http://localhost:5000/' const apiEndPoint = process.env.API_URL || 'http://localhost:5000/' let partes = url.split('/'); - let response = await fetch(apiEndPoint + "juguete/" + partes[partes.length - 1]); + let response = await fetch(apiEndPoint + "/juguete/" + partes[partes.length - 1]); //The objects returned by the api are directly convertible to User objects let j = response.json(); console.log(j); diff --git a/webapp/src/componentes/nuevoProducto/nuevoProducto.tsx b/webapp/src/componentes/nuevoProducto/nuevoProducto.tsx index 40e8a70..2edefb7 100644 --- a/webapp/src/componentes/nuevoProducto/nuevoProducto.tsx +++ b/webapp/src/componentes/nuevoProducto/nuevoProducto.tsx @@ -11,9 +11,9 @@ var imagen: string; var stock: number; async function addJuguete(): Promise { - const apiEndPoint = process.env.REACT_APP_API_URI || 'http://localhost:5000/' - //const apiEndPoint= process.env.REACT_APP_API_URI || 'https://dede-en2a-restapi.herokuapp.com' - let response = await fetch(apiEndPoint + "juguete", { + //const apiEndPoint = process.env.REACT_APP_API_URI || 'http://localhost:5000/' + const apiEndPoint = process.env.REACT_APP_API_URI || 'https://dede-es2a-restapi.herokuapp.com/' + let response = await fetch(apiEndPoint + "/juguete", { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({