diff --git a/.github/workflows/pruebaDeploy.ts b/.github/workflows/pruebaDeploy.ts new file mode 100644 index 0000000..5e2a46e --- /dev/null +++ b/.github/workflows/pruebaDeploy.ts @@ -0,0 +1,59 @@ +/* +name: CI for ASW2122 +on: + release: + 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 + steps: + - uses: actions/checkout@v2 + - name: Publish to Registry + uses: elgohr/Publish-Docker-Github-Action@3.04 + with: + name: arquisoft/dede_es2a/restapi + username: ${{ github.actor }} + 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" + 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" + */ \ No newline at end of file diff --git a/.github/workflows/pruebaSinDocker.yml b/.github/workflows/pruebaSinDocker.yml new file mode 100644 index 0000000..806b728 --- /dev/null +++ b/.github/workflows/pruebaSinDocker.yml @@ -0,0 +1,43 @@ +name: CI for ASW2122 +on: + release: + types: [published] +jobs: + deploy-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: + 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 }} 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/Dockerfile b/restapi/Dockerfile index e5a95f8..21e5856 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 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 0709b55..b61c72a 100644 --- a/restapi/modules/gestorDB.ts +++ b/restapi/modules/gestorDB.ts @@ -2,17 +2,16 @@ 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!, { + useNewUrlParser: true, + useUnifiedTopology: true }) .then(() =>{ console.log("Database connected") - }) - ; + }); } export function connectTest(){ diff --git a/restapi/server.ts b/restapi/server.ts index 6ec2d2d..f93363c 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}); @@ -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/Dockerfile b/webapp/Dockerfile index bca5e82..fbac2eb 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 diff --git a/webapp/package-lock.json b/webapp/package-lock.json index 5d747dc..8adb8ea 100644 --- a/webapp/package-lock.json +++ b/webapp/package-lock.json @@ -2717,10 +2717,9 @@ } }, "node_modules/@jest/console/node_modules/@jest/types": { - "version": "28.0.2", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-28.0.2.tgz", - "integrity": "sha512-hi3jUdm9iht7I2yrV5C4s3ucCJHUP8Eh3W6rQ1s4n/Qw9rQgsda4eqCt+r3BKRi7klVmZfQlMx1nGlzNMP2d8A==", - "dev": true, + "version": "28.0.1", + "resolved": "https://registry.npmjs.org/@jest/types/-/types-28.0.1.tgz", + "integrity": "sha512-Z48DBfQDtTZZAImaa1m8O1SCP9gx355FhuA6xuS8e7V5gQbj4l2hk/+EELN4UU/O9i5gjQuc94N/gC61/Qxfxw==", "dependencies": { "@jest/schemas": "^28.0.2", "@types/istanbul-lib-coverage": "^2.0.0", @@ -2801,10 +2800,9 @@ } }, "node_modules/@jest/console/node_modules/jest-message-util": { - "version": "28.0.2", - "resolved": "https://registry.npmjs.org/jest-message-util/-/jest-message-util-28.0.2.tgz", - "integrity": "sha512-knK7XyojvwYh1XiF2wmVdskgM/uN11KsjcEWWHfnMZNEdwXCrqB4sCBO94F4cfiAwCS8WFV6CDixDwPlMh/wdA==", - "dev": true, + "version": "28.0.1", + "resolved": "https://registry.npmjs.org/jest-message-util/-/jest-message-util-28.0.1.tgz", + "integrity": "sha512-Eb+s5Ow4MxcQb4gcIVWVdnLxCnaPrl6DZjOVe7MjKHhexmJlkVTdwvdC//YrAsJKWMU8eG2rdaGbgBk2zG2MLA==", "dependencies": { "@babel/code-frame": "^7.12.13", "@jest/types": "^28.0.2", @@ -2821,10 +2819,9 @@ } }, "node_modules/@jest/console/node_modules/jest-util": { - "version": "28.0.2", - "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-28.0.2.tgz", - "integrity": "sha512-EVdpIRCC8lzqhp9A0u0aAKlsFIzufK6xKxNK7awsnebTdOP4hpyQW5o6Ox2qPl8gbeUKYF+POLyItaND53kpGA==", - "dev": true, + "version": "28.0.1", + "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-28.0.1.tgz", + "integrity": "sha512-gFpqWx9XqBmJRYqSnQ2FbpxWpvAU3TIGFQcfBrwnMVvwbB1ZHhhoQgS+oD0Ek61l9XkLsoWW20woaNlCRf4eMA==", "dependencies": { "@jest/types": "^28.0.2", "@types/node": "*", @@ -2838,10 +2835,9 @@ } }, "node_modules/@jest/console/node_modules/pretty-format": { - "version": "28.0.2", - "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-28.0.2.tgz", - "integrity": "sha512-UmGZ1IERwS3yY35LDMTaBUYI1w4udZDdJGGT/DqQeKG9ZLDn7/K2Jf/JtYSRiHCCKMHvUA+zsEGSmHdpaVp1yw==", - "dev": true, + "version": "28.0.1", + "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-28.0.1.tgz", + "integrity": "sha512-utVSIy0ImophYyJALfiWULOeMnfoxLZEzii/92VcSzN7OX5U1r7erAMqfDJyuv31ugw4Rp5tOYUMndsZV1w8DQ==", "dependencies": { "@jest/schemas": "^28.0.2", "ansi-regex": "^5.0.1", @@ -2865,10 +2861,9 @@ } }, "node_modules/@jest/console/node_modules/react-is": { - "version": "18.1.0", - "resolved": "https://registry.npmjs.org/react-is/-/react-is-18.1.0.tgz", - "integrity": "sha512-Fl7FuabXsJnV5Q1qIOQwx/sagGF18kogb4gpfcG4gjLBWO0WDiiz1ko/ExayuxE7InyQkBLkxRFG5oxY6Uu3Kg==", - "dev": true + "version": "18.0.0", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-18.0.0.tgz", + "integrity": "sha512-yUcBYdBBbo3QiPsgYDcfQcIkGZHfxOaoE6HLSnr1sPzMhdyxusbfKOSUbSd/ocGi32dxcj366PsTj+5oggeKKw==" }, "node_modules/@jest/console/node_modules/supports-color": { "version": "7.2.0", @@ -3263,10 +3258,9 @@ } }, "node_modules/@jest/schemas": { - "version": "28.0.2", - "resolved": "https://registry.npmjs.org/@jest/schemas/-/schemas-28.0.2.tgz", - "integrity": "sha512-YVDJZjd4izeTDkij00vHHAymNXQ6WWsdChFRK86qck6Jpr3DCL5W3Is3vslviRlP+bLuMYRLbdp98amMvqudhA==", - "dev": true, + "version": "28.0.0", + "resolved": "https://registry.npmjs.org/@jest/schemas/-/schemas-28.0.0.tgz", + "integrity": "sha512-Pap9Jvwr8KYFvDgkya/p0FCVya+jZkWt57lHpwBylfjgmwi/gtXfhyAO/Cw+jKuMafHcXY0beNf2XV2pkcu9vA==", "dependencies": { "@sinclair/typebox": "^0.23.3" }, @@ -3298,10 +3292,9 @@ } }, "node_modules/@jest/test-result": { - "version": "28.0.2", - "resolved": "https://registry.npmjs.org/@jest/test-result/-/test-result-28.0.2.tgz", - "integrity": "sha512-4EUqgjq9VzyUiVTvZfI9IRJD6t3NYBNP4f+Eq8Zr93+hkJ0RrGU4OBTw8tfNzidKX+bmuYzn8FxqpxOPIGGCMA==", - "dev": true, + "version": "28.0.1", + "resolved": "https://registry.npmjs.org/@jest/test-result/-/test-result-28.0.1.tgz", + "integrity": "sha512-8LhoEbdIkkYK+PZx6JhfRvI1Jw7tfB77OEJUQwp0diBvXJpjPKeFFWfsbpm7djdXuKoKvXKNzSGgjXDOFbxuhg==", "dependencies": { "@jest/console": "^28.0.2", "@jest/types": "^28.0.2", @@ -3313,10 +3306,9 @@ } }, "node_modules/@jest/test-result/node_modules/@jest/types": { - "version": "28.0.2", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-28.0.2.tgz", - "integrity": "sha512-hi3jUdm9iht7I2yrV5C4s3ucCJHUP8Eh3W6rQ1s4n/Qw9rQgsda4eqCt+r3BKRi7klVmZfQlMx1nGlzNMP2d8A==", - "dev": true, + "version": "28.0.1", + "resolved": "https://registry.npmjs.org/@jest/types/-/types-28.0.1.tgz", + "integrity": "sha512-Z48DBfQDtTZZAImaa1m8O1SCP9gx355FhuA6xuS8e7V5gQbj4l2hk/+EELN4UU/O9i5gjQuc94N/gC61/Qxfxw==", "dependencies": { "@jest/schemas": "^28.0.2", "@types/istanbul-lib-coverage": "^2.0.0", @@ -12411,7 +12403,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" @@ -16602,10 +16593,9 @@ } }, "node_modules/jest-watcher": { - "version": "28.0.2", - "resolved": "https://registry.npmjs.org/jest-watcher/-/jest-watcher-28.0.2.tgz", - "integrity": "sha512-uIVJLpQ/5VTGQWBiBatHsi7jrCqHjHl0e0dFHMWzwuIfUbdW/muk0DtSr0fteY2T7QTFylv+7a5Rm8sBKrE12Q==", - "dev": true, + "version": "28.0.1", + "resolved": "https://registry.npmjs.org/jest-watcher/-/jest-watcher-28.0.1.tgz", + "integrity": "sha512-tKyjsQal10vBomcyn79ZTutv0N0/dSfYJ+WRFJ3nlaMejiDlLKjMGQ/QrcwcXIXMXQyt0tJG1ycmqLbJg5AK6A==", "dependencies": { "@jest/test-result": "^28.0.2", "@jest/types": "^28.0.2", @@ -16621,10 +16611,9 @@ } }, "node_modules/jest-watcher/node_modules/@jest/types": { - "version": "28.0.2", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-28.0.2.tgz", - "integrity": "sha512-hi3jUdm9iht7I2yrV5C4s3ucCJHUP8Eh3W6rQ1s4n/Qw9rQgsda4eqCt+r3BKRi7klVmZfQlMx1nGlzNMP2d8A==", - "dev": true, + "version": "28.0.1", + "resolved": "https://registry.npmjs.org/@jest/types/-/types-28.0.1.tgz", + "integrity": "sha512-Z48DBfQDtTZZAImaa1m8O1SCP9gx355FhuA6xuS8e7V5gQbj4l2hk/+EELN4UU/O9i5gjQuc94N/gC61/Qxfxw==", "dependencies": { "@jest/schemas": "^28.0.2", "@types/istanbul-lib-coverage": "^2.0.0", @@ -16705,10 +16694,9 @@ } }, "node_modules/jest-watcher/node_modules/jest-util": { - "version": "28.0.2", - "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-28.0.2.tgz", - "integrity": "sha512-EVdpIRCC8lzqhp9A0u0aAKlsFIzufK6xKxNK7awsnebTdOP4hpyQW5o6Ox2qPl8gbeUKYF+POLyItaND53kpGA==", - "dev": true, + "version": "28.0.1", + "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-28.0.1.tgz", + "integrity": "sha512-gFpqWx9XqBmJRYqSnQ2FbpxWpvAU3TIGFQcfBrwnMVvwbB1ZHhhoQgS+oD0Ek61l9XkLsoWW20woaNlCRf4eMA==", "dependencies": { "@jest/types": "^28.0.2", "@types/node": "*", @@ -27804,10 +27792,9 @@ "dev": true }, "@jest/console": { - "version": "28.0.2", - "resolved": "https://registry.npmjs.org/@jest/console/-/console-28.0.2.tgz", - "integrity": "sha512-tiRpnMeeyQuuzgL5UNSeiqMwF8UOWPbAE5rzcu/1zyq4oPG2Ox6xm4YCOruwbp10F8odWc+XwVxTyGzMSLMqxA==", - "dev": true, + "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==", "requires": { "@jest/types": "^28.0.2", "@types/node": "*", @@ -27818,10 +27805,9 @@ }, "dependencies": { "@jest/types": { - "version": "28.0.2", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-28.0.2.tgz", - "integrity": "sha512-hi3jUdm9iht7I2yrV5C4s3ucCJHUP8Eh3W6rQ1s4n/Qw9rQgsda4eqCt+r3BKRi7klVmZfQlMx1nGlzNMP2d8A==", - "dev": true, + "version": "28.0.1", + "resolved": "https://registry.npmjs.org/@jest/types/-/types-28.0.1.tgz", + "integrity": "sha512-Z48DBfQDtTZZAImaa1m8O1SCP9gx355FhuA6xuS8e7V5gQbj4l2hk/+EELN4UU/O9i5gjQuc94N/gC61/Qxfxw==", "requires": { "@jest/schemas": "^28.0.2", "@types/istanbul-lib-coverage": "^2.0.0", @@ -27881,10 +27867,9 @@ "dev": true }, "jest-message-util": { - "version": "28.0.2", - "resolved": "https://registry.npmjs.org/jest-message-util/-/jest-message-util-28.0.2.tgz", - "integrity": "sha512-knK7XyojvwYh1XiF2wmVdskgM/uN11KsjcEWWHfnMZNEdwXCrqB4sCBO94F4cfiAwCS8WFV6CDixDwPlMh/wdA==", - "dev": true, + "version": "28.0.1", + "resolved": "https://registry.npmjs.org/jest-message-util/-/jest-message-util-28.0.1.tgz", + "integrity": "sha512-Eb+s5Ow4MxcQb4gcIVWVdnLxCnaPrl6DZjOVe7MjKHhexmJlkVTdwvdC//YrAsJKWMU8eG2rdaGbgBk2zG2MLA==", "requires": { "@babel/code-frame": "^7.12.13", "@jest/types": "^28.0.2", @@ -27898,10 +27883,9 @@ } }, "jest-util": { - "version": "28.0.2", - "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-28.0.2.tgz", - "integrity": "sha512-EVdpIRCC8lzqhp9A0u0aAKlsFIzufK6xKxNK7awsnebTdOP4hpyQW5o6Ox2qPl8gbeUKYF+POLyItaND53kpGA==", - "dev": true, + "version": "28.0.1", + "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-28.0.1.tgz", + "integrity": "sha512-gFpqWx9XqBmJRYqSnQ2FbpxWpvAU3TIGFQcfBrwnMVvwbB1ZHhhoQgS+oD0Ek61l9XkLsoWW20woaNlCRf4eMA==", "requires": { "@jest/types": "^28.0.2", "@types/node": "*", @@ -27912,10 +27896,9 @@ } }, "pretty-format": { - "version": "28.0.2", - "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-28.0.2.tgz", - "integrity": "sha512-UmGZ1IERwS3yY35LDMTaBUYI1w4udZDdJGGT/DqQeKG9ZLDn7/K2Jf/JtYSRiHCCKMHvUA+zsEGSmHdpaVp1yw==", - "dev": true, + "version": "28.0.1", + "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-28.0.1.tgz", + "integrity": "sha512-utVSIy0ImophYyJALfiWULOeMnfoxLZEzii/92VcSzN7OX5U1r7erAMqfDJyuv31ugw4Rp5tOYUMndsZV1w8DQ==", "requires": { "@jest/schemas": "^28.0.2", "ansi-regex": "^5.0.1", @@ -27932,10 +27915,9 @@ } }, "react-is": { - "version": "18.1.0", - "resolved": "https://registry.npmjs.org/react-is/-/react-is-18.1.0.tgz", - "integrity": "sha512-Fl7FuabXsJnV5Q1qIOQwx/sagGF18kogb4gpfcG4gjLBWO0WDiiz1ko/ExayuxE7InyQkBLkxRFG5oxY6Uu3Kg==", - "dev": true + "version": "18.0.0", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-18.0.0.tgz", + "integrity": "sha512-yUcBYdBBbo3QiPsgYDcfQcIkGZHfxOaoE6HLSnr1sPzMhdyxusbfKOSUbSd/ocGi32dxcj366PsTj+5oggeKKw==" }, "supports-color": { "version": "7.2.0", @@ -28236,10 +28218,9 @@ } }, "@jest/schemas": { - "version": "28.0.2", - "resolved": "https://registry.npmjs.org/@jest/schemas/-/schemas-28.0.2.tgz", - "integrity": "sha512-YVDJZjd4izeTDkij00vHHAymNXQ6WWsdChFRK86qck6Jpr3DCL5W3Is3vslviRlP+bLuMYRLbdp98amMvqudhA==", - "dev": true, + "version": "28.0.0", + "resolved": "https://registry.npmjs.org/@jest/schemas/-/schemas-28.0.0.tgz", + "integrity": "sha512-Pap9Jvwr8KYFvDgkya/p0FCVya+jZkWt57lHpwBylfjgmwi/gtXfhyAO/Cw+jKuMafHcXY0beNf2XV2pkcu9vA==", "requires": { "@sinclair/typebox": "^0.23.3" } @@ -28264,10 +28245,9 @@ } }, "@jest/test-result": { - "version": "28.0.2", - "resolved": "https://registry.npmjs.org/@jest/test-result/-/test-result-28.0.2.tgz", - "integrity": "sha512-4EUqgjq9VzyUiVTvZfI9IRJD6t3NYBNP4f+Eq8Zr93+hkJ0RrGU4OBTw8tfNzidKX+bmuYzn8FxqpxOPIGGCMA==", - "dev": true, + "version": "28.0.1", + "resolved": "https://registry.npmjs.org/@jest/test-result/-/test-result-28.0.1.tgz", + "integrity": "sha512-8LhoEbdIkkYK+PZx6JhfRvI1Jw7tfB77OEJUQwp0diBvXJpjPKeFFWfsbpm7djdXuKoKvXKNzSGgjXDOFbxuhg==", "requires": { "@jest/console": "^28.0.2", "@jest/types": "^28.0.2", @@ -28276,10 +28256,9 @@ }, "dependencies": { "@jest/types": { - "version": "28.0.2", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-28.0.2.tgz", - "integrity": "sha512-hi3jUdm9iht7I2yrV5C4s3ucCJHUP8Eh3W6rQ1s4n/Qw9rQgsda4eqCt+r3BKRi7klVmZfQlMx1nGlzNMP2d8A==", - "dev": true, + "version": "28.0.1", + "resolved": "https://registry.npmjs.org/@jest/types/-/types-28.0.1.tgz", + "integrity": "sha512-Z48DBfQDtTZZAImaa1m8O1SCP9gx355FhuA6xuS8e7V5gQbj4l2hk/+EELN4UU/O9i5gjQuc94N/gC61/Qxfxw==", "requires": { "@jest/schemas": "^28.0.2", "@types/istanbul-lib-coverage": "^2.0.0", @@ -35149,7 +35128,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" @@ -38320,10 +38298,9 @@ } }, "jest-watcher": { - "version": "28.0.2", - "resolved": "https://registry.npmjs.org/jest-watcher/-/jest-watcher-28.0.2.tgz", - "integrity": "sha512-uIVJLpQ/5VTGQWBiBatHsi7jrCqHjHl0e0dFHMWzwuIfUbdW/muk0DtSr0fteY2T7QTFylv+7a5Rm8sBKrE12Q==", - "dev": true, + "version": "28.0.1", + "resolved": "https://registry.npmjs.org/jest-watcher/-/jest-watcher-28.0.1.tgz", + "integrity": "sha512-tKyjsQal10vBomcyn79ZTutv0N0/dSfYJ+WRFJ3nlaMejiDlLKjMGQ/QrcwcXIXMXQyt0tJG1ycmqLbJg5AK6A==", "requires": { "@jest/test-result": "^28.0.2", "@jest/types": "^28.0.2", @@ -38336,10 +38313,9 @@ }, "dependencies": { "@jest/types": { - "version": "28.0.2", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-28.0.2.tgz", - "integrity": "sha512-hi3jUdm9iht7I2yrV5C4s3ucCJHUP8Eh3W6rQ1s4n/Qw9rQgsda4eqCt+r3BKRi7klVmZfQlMx1nGlzNMP2d8A==", - "dev": true, + "version": "28.0.1", + "resolved": "https://registry.npmjs.org/@jest/types/-/types-28.0.1.tgz", + "integrity": "sha512-Z48DBfQDtTZZAImaa1m8O1SCP9gx355FhuA6xuS8e7V5gQbj4l2hk/+EELN4UU/O9i5gjQuc94N/gC61/Qxfxw==", "requires": { "@jest/schemas": "^28.0.2", "@types/istanbul-lib-coverage": "^2.0.0", @@ -38399,10 +38375,9 @@ "dev": true }, "jest-util": { - "version": "28.0.2", - "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-28.0.2.tgz", - "integrity": "sha512-EVdpIRCC8lzqhp9A0u0aAKlsFIzufK6xKxNK7awsnebTdOP4hpyQW5o6Ox2qPl8gbeUKYF+POLyItaND53kpGA==", - "dev": true, + "version": "28.0.1", + "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-28.0.1.tgz", + "integrity": "sha512-gFpqWx9XqBmJRYqSnQ2FbpxWpvAU3TIGFQcfBrwnMVvwbB1ZHhhoQgS+oD0Ek61l9XkLsoWW20woaNlCRf4eMA==", "requires": { "@jest/types": "^28.0.2", "@types/node": "*", diff --git a/webapp/package.json b/webapp/package.json index ca625b7..7b7a679 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-puppeteer": "^6.1.0", "react": "^17.0.2", diff --git a/webapp/src/App.tsx b/webapp/src/App.tsx index 580f754..7b5664a 100644 --- a/webapp/src/App.tsx +++ b/webapp/src/App.tsx @@ -29,6 +29,7 @@ import EditForm from './componentes/editarProducto/editarProducto'; import CategoriesBar from './PayForm/CategoriesBar'; import AddForm from './componentes/nuevoProducto/nuevoProducto'; + //Types export type CartItemType = { id: number; @@ -52,14 +53,10 @@ 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' - let response = await fetch(apiEndPoint + 'juguete/withstock'); + //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(); @@ -80,7 +77,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 +151,6 @@ const App = () => { }; - //Coloca una barra de carga cuando la página está cargando - //if (isLoading) return ; - //if (error) return
Algo ha fallado
; - return ( <> diff --git a/webapp/src/Item/Item.tsx b/webapp/src/Item/Item.tsx index fecdf1d..4a015b4 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/api/api.ts b/webapp/src/api/api.ts index 966ba1e..2b1f33e 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,8 +14,9 @@ export async function addUser(user:User):Promise{ return false; } + 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() diff --git a/webapp/src/componentes/Pedidos/historial.tsx b/webapp/src/componentes/Pedidos/historial.tsx index ed53ca7..980480e 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 ca62064..8fa3e84 100644 --- a/webapp/src/componentes/editarProducto/editarProducto.tsx +++ b/webapp/src/componentes/editarProducto/editarProducto.tsx @@ -12,11 +12,10 @@ 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]); + 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); @@ -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', diff --git a/webapp/src/componentes/nuevoProducto/nuevoProducto.tsx b/webapp/src/componentes/nuevoProducto/nuevoProducto.tsx index 64f17d7..aa1c34b 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({