From ff2b3bf2079ae38a1ee447d941d1e2e6f248481f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Rialland?= Date: Wed, 8 Jun 2022 11:03:14 +0200 Subject: [PATCH] Ajout du support des review apps pour l'api --- .github/workflows/deploy.yaml | 4 ++++ api/package.json | 2 +- site/netlify.toml | 4 ++-- site/package.json | 4 ++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 012e8d75e..86a4436ee 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -21,6 +21,7 @@ jobs: runs-on: ubuntu-18.04 outputs: env-name: ${{ steps.deploy-env.outputs.name }} + api_url: ${{ steps.base-urls.outputs.api }} fr_url: ${{ steps.base-urls.outputs.fr }} en_url: ${{ steps.base-urls.outputs.en }} steps: @@ -28,12 +29,14 @@ jobs: run: echo "::set-output name=name::${{ github.event.number || '${GITHUB_REF#refs/*/}' }}" - id: base-urls run: + echo "::set-output name=api::${{ steps.deploy-env.outputs.name == 'master' && 'https://mon-entreprise-api.osc-fr1.scalingo.io' || format('https://mon-entreprise-api-pr{0}.osc-fr1.scalingo.io', steps.deploy-env.outputs.name) }}"; echo "::set-output name=fr::${{ steps.deploy-env.outputs.name == 'master' && 'https://mon-entreprise.urssaf.fr' || format('https://{0}--mon-entreprise.netlify.app', steps.deploy-env.outputs.name) }}"; echo "::set-output name=en::${{ steps.deploy-env.outputs.name == 'master' && 'https://mycompanyinfrance.urssaf.fr' || format('https://{0}-en--mon-entreprise.netlify.app', steps.deploy-env.outputs.name) }}"; build: needs: deploy-context env: + API_BASE_URL: ${{ needs.deploy-context.outputs.api_url }} VITE_FR_BASE_URL: ${{ needs.deploy-context.outputs.fr_url }} VITE_EN_BASE_URL: ${{ needs.deploy-context.outputs.en_url }} runs-on: ubuntu-18.04 @@ -62,6 +65,7 @@ jobs: yarn workspace site build:prerender - name: Replace site placeholders in netlify.toml redirection file run: | + sed -i "s|:API_URL|$API_BASE_URL|g" site/netlify.toml; sed -i "s|:SITE_FR|$VITE_FR_BASE_URL|g" site/netlify.toml; sed -i "s|:SITE_EN|$VITE_EN_BASE_URL|g" site/netlify.toml; - name: Update Algolia index diff --git a/api/package.json b/api/package.json index ead3aff85..5375f3b4f 100644 --- a/api/package.json +++ b/api/package.json @@ -17,7 +17,7 @@ "validate": "yarn swagger-cli validate ./source/openapi.yaml", "postinstall": "yarn build:openapi", "start": "yarn clean && yarn build:watch & wait-on ./dist && nodemon -d 1s ./dist/", - "start:prod": "nodemon -d 500ms -w ./dist/index.js -x 'node ./dist/index.js || touch ./dist/index.js'", + "start:prod": "NODE_ENV=production nodemon -d 500ms -w ./dist/index.js -x 'node ./dist/index.js || touch ./dist/index.js'", "build": "yarn build:openapi && yarn build:ts", "build:watch": "yarn build:openapi:watch & yarn wait:openapi && yarn build:ts:watch", "build:ts": "tsc", diff --git a/site/netlify.toml b/site/netlify.toml index 31aedbba1..71eee1eb2 100644 --- a/site/netlify.toml +++ b/site/netlify.toml @@ -1,12 +1,12 @@ [[headers]] for = "/*" [headers.values] -Content-Security-Policy = "default-src 'self' mon-entreprise.fr; style-src 'self' 'unsafe-inline' mon-entreprise.zammad.com; connect-src 'self' *.incubateur.net raw.githubusercontent.com tm.urssaf.fr mon-entreprise.zammad.com api.recherche-entreprises.fabrique.social.gouv.fr geo.api.gouv.fr *.algolia.net *.algolianet.com; form-action 'self' *.sibforms.com *.incubateur.net mon-entreprise.zammad.com; script-src 'self' 'unsafe-inline' 'unsafe-eval' tm.urssaf.fr *.incubateur.net stonly.com code.jquery.com mon-entreprise.zammad.com polyfill.io; img-src 'self' data: tm.urssaf.fr user-images.githubusercontent.com; frame-src 'self' https://www.youtube-nocookie.com https://codesandbox.io https://place-des-entreprises.beta.gouv.fr https://reso-staging.osc-fr1.scalingo.io" +Content-Security-Policy = "default-src 'self' mon-entreprise.fr; style-src 'self' 'unsafe-inline' mon-entreprise.zammad.com; connect-src 'self' *.incubateur.net raw.githubusercontent.com tm.urssaf.fr mon-entreprise.zammad.com api.recherche-entreprises.fabrique.social.gouv.fr geo.api.gouv.fr *.algolia.net *.algolianet.com; form-action 'self' *.sibforms.com *.incubateur.net mon-entreprise.zammad.com; script-src 'self' 'unsafe-inline' 'unsafe-eval' tm.urssaf.fr *.incubateur.net stonly.com code.jquery.com mon-entreprise.zammad.com polyfill.io; img-src 'self' data: tm.urssaf.fr user-images.githubusercontent.com; frame-src 'self' https://www.youtube-nocookie.com https://codesandbox.io https://place-des-entreprises.beta.gouv.fr https://reso-staging.osc-fr1.scalingo.io https://stackblitz.com" ## Scalingo proxy for API [[redirects]] from = "/api/*" - to = "https://mon-entreprise-api.osc-fr1.scalingo.io/api/:splat" + to = ":API_URL/api/:splat" status = 200 ## Twemoji proxy for client privacy #1219 diff --git a/site/package.json b/site/package.json index da24c6231..6c4b27d7b 100644 --- a/site/package.json +++ b/site/package.json @@ -27,8 +27,8 @@ "build:prerender": "node prerender.cjs", "build:iframe-script": "NODE_OPTIONS='--max-old-space-size=4096'; vite build --config vite-iframe-script.config.ts", "build:preview": "VITE_FR_BASE_URL=http://localhost:8888; VITE_EN_BASE_URL=http://localhost:8889; yarn build && yarn build:ssr && yarn build:prerender", - "preview:mon-entreprise": "sed 's|:SITE_FR||g' netlify.toml > dist/netlify.toml && cd dist && npx netlify-cli dev -p 8888", - "preview:infrance": "sed 's|:SITE_EN||g' netlify.toml > dist/netlify.toml && cd dist && npx netlify-cli dev -p 8889", + "preview:mon-entreprise": "sed 's|:SITE_FR||g' netlify.toml | sed 's|:API_URL|http://localhost:3004|g' > dist/netlify.toml && cd dist && npx netlify-cli dev -d ./ -p 8888", + "preview:infrance": "sed 's|:SITE_EN||g' | sed 's|:API_URL|http://localhost:3004|g' netlify.toml > dist/netlify.toml && cd dist && npx netlify-cli dev -d ./ -p 8889", "typecheck:watch": "tsc --skipLibCheck --noEmit --watch", "test": "vitest", "test:dev-e2e:mon-entreprise": "cypress open --browser chromium",