Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add web.config for IIS deployment of the client #805

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>