Skip to content

Commit

Permalink
Add web.config for IIS deployement of the client
Browse files Browse the repository at this point in the history
  • Loading branch information
emmguyot committed Oct 26, 2024
1 parent 14dff96 commit a7c126c
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 2 deletions.
3 changes: 3 additions & 0 deletions client/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#REACT_APP_SERVER_BASE_URL=https://...
#PUBLIC_URL=https://...
#BASE_URL=/.../
24 changes: 22 additions & 2 deletions client/config-overrides.js
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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);
}
}
});
Expand All @@ -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;
Expand Down
105 changes: 105 additions & 0 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 17 additions & 0 deletions client/public/web.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="React Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="BASE_URL_PLACEHOLDER" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

0 comments on commit a7c126c

Please sign in to comment.