From a7c126ce262c806192ac3989e4047139924dd40d Mon Sep 17 00:00:00 2001 From: Emmanuel Guyot Date: Sat, 22 Jun 2024 19:13:15 +0200 Subject: [PATCH] Add web.config for IIS deployement of the client --- client/.env | 3 ++ client/config-overrides.js | 24 ++++++++- client/package-lock.json | 105 +++++++++++++++++++++++++++++++++++++ client/package.json | 1 + client/public/web.config | 17 ++++++ 5 files changed, 148 insertions(+), 2 deletions(-) create mode 100644 client/.env create mode 100755 client/public/web.config diff --git a/client/.env b/client/.env new file mode 100644 index 000000000..1612d206c --- /dev/null +++ b/client/.env @@ -0,0 +1,3 @@ +#REACT_APP_SERVER_BASE_URL=https://... +#PUBLIC_URL=https://... +#BASE_URL=/.../ diff --git a/client/config-overrides.js b/client/config-overrides.js index 2ea9da5d8..115e75a4e 100644 --- a/client/config-overrides.js +++ b/client/config-overrides.js @@ -1,5 +1,6 @@ const fs = require('fs'); const path = require('path'); +const CopyPlugin = require('copy-webpack-plugin'); const BASE_URL_PLACEHOLDER = 'BASE_URL_PLACEHOLDER'; @@ -32,7 +33,7 @@ const replaceBaseUrl = (compiler) => { replaceInFile(info.targetPath, `"${BASE_URL_PLACEHOLDER}"`, '`${window.BASE_URL}/`'); } else if (/index\.html$/.exec(info.targetPath)) { // For the main html file, we set a placeholder for sails to inject the correct value as runtime - replaceInFile(info.targetPath, BASE_URL_PLACEHOLDER, '<%= BASE_URL %>'); + replaceInFile(info.targetPath, BASE_URL_PLACEHOLDER, process.env.PUBLIC_URL); } } }); @@ -51,7 +52,26 @@ module.exports = function override(config, env) { return { ...config, output: { ...config.output, publicPath: BASE_URL_PLACEHOLDER }, - plugins: [...plugins, { apply: replaceBaseUrl }], + plugins: [ + ...plugins, + { apply: replaceBaseUrl }, + new CopyPlugin({ + patterns: [ + { + from: 'public/web.config', + transform: { + transformer(content, absoluteFrom) { + const PUBLIC_PATH = process.env.PUBLIC_URL.replace( + /^.*\/\/[^/]*(.*)[^?#]*.*$/, + '$1', + ); + return content.toString().replaceAll(BASE_URL_PLACEHOLDER, PUBLIC_PATH); + }, + }, + }, + ], + }), + ], }; } return config; diff --git a/client/package-lock.json b/client/package-lock.json index c1b5158b7..aa649da63 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -64,6 +64,7 @@ "axios": "^1.6.2", "babel-preset-airbnb": "^5.0.0", "chai": "^4.5.0", + "copy-webpack-plugin": "^12.0.2", "eslint": "^8.57.0", "eslint-config-airbnb": "^19.0.4", "eslint-plugin-import": "^2.30.0", @@ -4092,6 +4093,30 @@ "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.24.51.tgz", "integrity": "sha512-1P1OROm/rdubP5aFDSZQILU0vrLCJ4fvHt6EoqHEM+2D/G5MK3bIaymUKLit8Js9gbns5UyJnkP/TZROLw4tUA==" }, + "node_modules/@sindresorhus/merge-streams": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/@sindresorhus/merge-streams/-/merge-streams-2.3.0.tgz", + "integrity": "sha512-LtoMMhxAlorcGhmFYI+LhPgbPZCkgP6ra1YL604EeF6U98pLlQ3iWIGMdWSC+vWmPBWBNgmDBAhnAobLROJmwg==", + "dev": true, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/@sindresorhus/merge-streams": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/@sindresorhus/merge-streams/-/merge-streams-2.3.0.tgz", + "integrity": "sha512-LtoMMhxAlorcGhmFYI+LhPgbPZCkgP6ra1YL604EeF6U98pLlQ3iWIGMdWSC+vWmPBWBNgmDBAhnAobLROJmwg==", + "dev": true, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/@sinonjs/commons": { "version": "1.8.6", "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.6.tgz", @@ -7304,6 +7329,74 @@ "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", "integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==" }, + "node_modules/copy-webpack-plugin": { + "version": "12.0.2", + "resolved": "https://registry.npmjs.org/copy-webpack-plugin/-/copy-webpack-plugin-12.0.2.tgz", + "integrity": "sha512-SNwdBeHyII+rWvee/bTnAYyO8vfVdcSTud4EIb6jcZ8inLeWucJE0DnxXQBjlQ5zlteuuvooGQy3LIyGxhvlOA==", + "dev": true, + "dependencies": { + "fast-glob": "^3.3.2", + "glob-parent": "^6.0.1", + "globby": "^14.0.0", + "normalize-path": "^3.0.0", + "schema-utils": "^4.2.0", + "serialize-javascript": "^6.0.2" + }, + "engines": { + "node": ">= 18.12.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/webpack" + }, + "peerDependencies": { + "webpack": "^5.1.0" + } + }, + "node_modules/copy-webpack-plugin/node_modules/globby": { + "version": "14.0.1", + "resolved": "https://registry.npmjs.org/globby/-/globby-14.0.1.tgz", + "integrity": "sha512-jOMLD2Z7MAhyG8aJpNOpmziMOP4rPLcc95oQPKXBazW82z+CEgPFBQvEpRUa1KeIMUJo4Wsm+q6uzO/Q/4BksQ==", + "dev": true, + "dependencies": { + "@sindresorhus/merge-streams": "^2.1.0", + "fast-glob": "^3.3.2", + "ignore": "^5.2.4", + "path-type": "^5.0.0", + "slash": "^5.1.0", + "unicorn-magic": "^0.1.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/copy-webpack-plugin/node_modules/path-type": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/path-type/-/path-type-5.0.0.tgz", + "integrity": "sha512-5HviZNaZcfqP95rwpv+1HDgUamezbqdSYTyzjTvwtJSnIH+3vnbmWsItli8OFEndS984VT55M3jduxZbX351gg==", + "dev": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/copy-webpack-plugin/node_modules/slash": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/slash/-/slash-5.1.0.tgz", + "integrity": "sha512-ZA6oR3T/pEyuqwMgAKT0/hAv8oAXckzbkmR0UkUosQ+Mc4RxGoJkRmwHgHufaenlyAgE1Mxgpdcrf75y6XcnDg==", + "dev": true, + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/core-js": { "version": "3.38.1", "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.38.1.tgz", @@ -22360,6 +22453,18 @@ "node": ">=4" } }, + "node_modules/unicorn-magic": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/unicorn-magic/-/unicorn-magic-0.1.0.tgz", + "integrity": "sha512-lRfVq8fE8gz6QMBuDM6a+LO3IAzTi05H6gCVaUpir2E1Rwpo4ZUog45KpNXKC/Mn3Yb9UDuHumeFTo9iV/D9FQ==", + "dev": true, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/unified": { "version": "10.1.2", "resolved": "https://registry.npmjs.org/unified/-/unified-10.1.2.tgz", diff --git a/client/package.json b/client/package.json index d80ee4bff..2a891b719 100755 --- a/client/package.json +++ b/client/package.json @@ -118,6 +118,7 @@ "axios": "^1.6.2", "babel-preset-airbnb": "^5.0.0", "chai": "^4.5.0", + "copy-webpack-plugin": "^12.0.2", "eslint": "^8.57.0", "eslint-config-airbnb": "^19.0.4", "eslint-plugin-import": "^2.30.0", diff --git a/client/public/web.config b/client/public/web.config new file mode 100755 index 000000000..7d5e4b81d --- /dev/null +++ b/client/public/web.config @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + +